<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
  xmlns:widget="http://www.netvibes.com/ns/">
<head>
<title>MSN-Gadget</title>
<meta name="debugMode" content="true" />

<link rel="stylesheet" type="text/css" 
  href="http://www.netvibes.com/themes/uwa/style.css" />
<script type="text/javascript" 
  src="http://www.netvibes.com/js/UWA/load.js.php?env=Standalone"></script>
  
<script type="text/javascript" language="javascript">
// v2.0.40814.0
if(!window.Silverlight)window.Silverlight={};Silverlight._silverlightCount=0;Silverlight.__onSilverlightInstalledCalled=false;Silverlight.fwlinkRoot="http://go2.microsoft.com/fwlink/?LinkID=";Silverlight.__installationEventFired=false;Silverlight.onGetSilverlight=null;Silverlight.onSilverlightInstalled=function(){window.location.reload(false)};Silverlight.isInstalled=function(b){if(b==undefined)b=null;var a=false,m=null;try{var i=null,j=false;if(window.ActiveXObject)try{i=new ActiveXObject("AgControl.AgControl");if(b===null)a=true;else if(i.IsVersionSupported(b))a=true;i=null}catch(l){j=true}else j=true;if(j){var k=navigator.plugins["Silverlight Plug-In"];if(k)if(b===null)a=true;else{var h=k.description;if(h==="1.0.30226.2")h="2.0.30226.2";var c=h.split(".");while(c.length>3)c.pop();while(c.length<4)c.push(0);var e=b.split(".");while(e.length>4)e.pop();var d,g,f=0;do{d=parseInt(e[f]);g=parseInt(c[f]);f++}while(f<e.length&&d===g);if(d<=g&&!isNaN(d))a=true}}}catch(l){a=false}return a};Silverlight.WaitForInstallCompletion=function(){if(!Silverlight.isBrowserRestartRequired&&Silverlight.onSilverlightInstalled){try{navigator.plugins.refresh()}catch(a){}if(Silverlight.isInstalled(null)&&!Silverlight.__onSilverlightInstalledCalled){Silverlight.onSilverlightInstalled();Silverlight.__onSilverlightInstalledCalled=true}else setTimeout(Silverlight.WaitForInstallCompletion,3e3)}};Silverlight.__startup=function(){navigator.plugins.refresh();Silverlight.isBrowserRestartRequired=Silverlight.isInstalled(null);if(!Silverlight.isBrowserRestartRequired){Silverlight.WaitForInstallCompletion();if(!Silverlight.__installationEventFired){Silverlight.onInstallRequired();Silverlight.__installationEventFired=true}}else if(window.navigator.mimeTypes){var b=navigator.mimeTypes["application/x-silverlight-2"],c=navigator.mimeTypes["application/x-silverlight-2-b2"],d=navigator.mimeTypes["application/x-silverlight-2-b1"],a=d;if(c)a=c;if(!b&&(d||c)){if(!Silverlight.__installationEventFired){Silverlight.onUpgradeRequired();Silverlight.__installationEventFired=true}}else if(b&&a)if(b.enabledPlugin&&a.enabledPlugin)if(b.enabledPlugin.description!=a.enabledPlugin.description)if(!Silverlight.__installationEventFired){Silverlight.onRestartRequired();Silverlight.__installationEventFired=true}}if(!Silverlight.disableAutoStartup)if(window.removeEventListener)window.removeEventListener("load",Silverlight.__startup,false);else window.detachEvent("onload",Silverlight.__startup)};if(!Silverlight.disableAutoStartup)if(window.addEventListener)window.addEventListener("load",Silverlight.__startup,false);else window.attachEvent("onload",Silverlight.__startup);Silverlight.createObject=function(m,f,e,k,l,h,j){var d={},a=k,c=l;d.version=a.version;a.source=m;d.alt=a.alt;if(h)a.initParams=h;if(a.isWindowless&&!a.windowless)a.windowless=a.isWindowless;if(a.framerate&&!a.maxFramerate)a.maxFramerate=a.framerate;if(e&&!a.id)a.id=e;delete a.ignoreBrowserVer;delete a.inplaceInstallPrompt;delete a.version;delete a.isWindowless;delete a.framerate;delete a.data;delete a.src;delete a.alt;if(Silverlight.isInstalled(d.version)){for(var b in c)if(c[b]){if(b=="onLoad"&&typeof c[b]=="function"&&c[b].length!=1){var i=c[b];c[b]=function(a){return i(document.getElementById(e),j,a)}}var g=Silverlight.__getHandlerName(c[b]);if(g!=null){a[b]=g;c[b]=null}else throw"typeof events."+b+" must be 'function' or 'string'";}slPluginHTML=Silverlight.buildHTML(a)}else slPluginHTML=Silverlight.buildPromptHTML(d);if(f)f.innerHTML=slPluginHTML;else return slPluginHTML};Silverlight.buildHTML=function(a){var b=[];b.push('<object type="application/x-silverlight" data="data:application/x-silverlight,"');if(a.id!=null)b.push(' id="'+Silverlight.HtmlAttributeEncode(a.id)+'"');if(a.width!=null)b.push(' width="'+a.width+'"');if(a.height!=null)b.push(' height="'+a.height+'"');b.push(" >");delete a.id;delete a.width;delete a.height;for(var c in a)if(a[c])b.push('<param name="'+Silverlight.HtmlAttributeEncode(c)+'" value="'+Silverlight.HtmlAttributeEncode(a[c])+'" />');b.push("</object>");return b.join("")};Silverlight.createObjectEx=function(b){var a=b,c=Silverlight.createObject(a.source,a.parentElement,a.id,a.properties,a.events,a.initParams,a.context);if(a.parentElement==null)return c};Silverlight.buildPromptHTML=function(b){var a="",d=Silverlight.fwlinkRoot,c=b.version;if(b.alt)a=b.alt;else{if(!c)c="";a="<a href='javascript:Silverlight.getSilverlight(\"{1}\");' style='text-decoration: none;'><img src='{2}' alt='Get Microsoft Silverlight' style='border-style: none'/></a>";a=a.replace("{1}",c);a=a.replace("{2}",d+"108181")}return a};Silverlight.getSilverlight=function(e){if(Silverlight.onGetSilverlight)Silverlight.onGetSilverlight();var b="",a=String(e).split(".");if(a.length>1){var c=parseInt(a[0]);if(isNaN(c)||c<2)b="1.0";else b=a[0]+"."+a[1]}var d="";if(b.match(/^\d+\056\d+$/))d="&v="+b;Silverlight.followFWLink("149156"+d)};Silverlight.followFWLink=function(a){top.location=Silverlight.fwlinkRoot+String(a)};Silverlight.HtmlAttributeEncode=function(c){var a,b="";if(c==null)return null;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);if(a>96&&a<123||a>64&&a<91||a>43&&a<58&&a!=47||a==95)b=b+String.fromCharCode(a);else b=b+"&#"+a+";"}return b};Silverlight.default_error_handler=function(e,b){var d,c=b.ErrorType;d=b.ErrorCode;var a="\nSilverlight error message     \n";a+="ErrorCode: "+d+"\n";a+="ErrorType: "+c+"       \n";a+="Message: "+b.ErrorMessage+"     \n";if(c=="ParserError"){a+="XamlFile: "+b.xamlFile+"     \n";a+="Line: "+b.lineNumber+"     \n";a+="Position: "+b.charPosition+"     \n"}else if(c=="RuntimeError"){if(b.lineNumber!=0){a+="Line: "+b.lineNumber+"     \n";a+="Position: "+b.charPosition+"     \n"}a+="MethodName: "+b.methodName+"     \n"}alert(a)};Silverlight.__cleanup=function(){for(var a=Silverlight._silverlightCount-1;a>=0;a--)window["__slEvent"+a]=null;Silverlight._silverlightCount=0;if(window.removeEventListener)window.removeEventListener("unload",Silverlight.__cleanup,false);else window.detachEvent("onunload",Silverlight.__cleanup)};Silverlight.__getHandlerName=function(b){var a="";if(typeof b=="string")a=b;else if(typeof b=="function"){if(Silverlight._silverlightCount==0)if(window.addEventListener)window.addEventListener("unload",Silverlight.__cleanup,false);else window.attachEvent("onunload",Silverlight.__cleanup);var c=Silverlight._silverlightCount++;a="__slEvent"+c;window[a]=b}else a=null;return a};Silverlight.onRequiredVersionAvailable=function(){};Silverlight.onRestartRequired=function(){};Silverlight.onUpgradeRequired=function(){};Silverlight.onInstallRequired=function(){};Silverlight.IsVersionAvailableOnError=function(d,a){var b=false;try{if(a.ErrorCode==8001&&!Silverlight.__installationEventFired){Silverlight.onUpgradeRequired();Silverlight.__installationEventFired=true}else if(a.ErrorCode==8002&&!Silverlight.__installationEventFired){Silverlight.onRestartRequired();Silverlight.__installationEventFired=true}else if(a.ErrorCode==5014||a.ErrorCode==2106){if(Silverlight.__verifySilverlight2UpgradeSuccess(a.getHost()))b=true}else b=true}catch(c){}return b};Silverlight.IsVersionAvailableOnLoad=function(b){var a=false;try{if(Silverlight.__verifySilverlight2UpgradeSuccess(b.getHost()))a=true}catch(c){}return a};Silverlight.__verifySilverlight2UpgradeSuccess=function(d){var c=false,b="3.0.40723",a=null;try{if(d.IsVersionSupported(b+".99")){a=Silverlight.onRequiredVersionAvailable;c=true}else if(d.IsVersionSupported(b+".0"))a=Silverlight.onRestartRequired;else a=Silverlight.onUpgradeRequired;if(a&&!Silverlight.__installationEventFired){a();Silverlight.__installationEventFired=true}}catch(e){}return c}
 
/************************************************************************************
* This file contains some configurations, which alter the appearance or functionality 
* of the gadget
************************************************************************************/

var config = {};
config.image_str = "http://msnwidget.googlecode.com/svn/trunk/gadget2/images/";
config.weather_image_str = config.image_str + "weather/";
config.bg_color = new Array("#000000", "#151530", "#1b0041", "#A66200", "#500000", "#004006", "#740062"
                          , "#283a19", "#7e3b00", "#006654", "#2a2318", "#2c5876");
config.bg_color2 = new Array("CCCCCC", "6DC0fB", "964df5", "ffC640", "d90000", "9eDfAd", "ebb5ff"
                          , "cef7ca", "ffa555", "55ffe5", "c6ae84", "9ad0fd");

config.trackingURL = "http://estj.msn.com/br/om/js/s_code.js";
var s_account = "";

config.news = {};

//How many newsitems are shown in the undocked state
config.news.limit_undocked = 5;

//How many newsitems are shown in the docked state
config.news.limit_docked = 5;

//The height of a single newsitem in undocked state
config.news.height = 30;

//The height of a single newsitem in docked state
config.news.height_docked = 20;

//The top-margin of the newsitems, in the docked state
config.news.top_docked = 19;

//The top-margin of the newsitems, in the undocked state
config.news.top_undocked = 30;

//The color of a newsitem, when it has no focus
config.news.hl_color = "#faaa";

//The color of a newsitem, when it has focus
config.news.hl_color_focus = "#feee";

//If true, the flyout opens by mouseover, otherwise with a mouseclick
config.news.mouseover = false;

//The time in milliseconds, which lies between the news-cycles
config.news.cycletime = 30000;

config.video = {};
config.video.small_top = -10;

//The deafult-weather
config.weather = {};
config.weather.defaultCode = "wc:GMXX0007";
config.weather.defaultName = "Berlin";

//The time in minutes where the weather is refreshed
config.weather.refreshTime = 30;

config.searchbar = {};
config.searchbar.itemWidth = 45.5;
config.searchbar.itemWidth_docked = 38;
config.searchbar.itemSpace = 2.6;
config.searchbar.itemSpace_docked = 1.6;

/* Localisation for the MSN-Gadget
   Replace this file with the one of the desired language 
   
    IMPORTANT NOTE:
    Every String, that contains a special charakter from the ISO 8859-1 Set (Latin-1), has to be escaped.
    Replace the special character with its hexdecimal representation (e.g. "ä" = "%E4") and call unescape() on that string.

    A listing can be found here: http://en.wikipedia.org/wiki/ISO/IEC_8859-1#Codepage_layout
*/

//The tracking-ids for a clickthrough and a pageview (when user watches the preview of an article), respectively
var ocid_1 = "bmm_gadget_";
var ocid_ct = "_clickthrough";
var ocid_pv = "_pageview";
var ocid = "bmm_gadget_clickthrough";
var ocid_pv = "bmm_gadget_pageview";

var locale = {};

locale.news_limit_docked = 4;
locale.news_limit_undocked = 5;
locale.news_no_description = "Keine Vorschau vorhanden.";
locale.getToolbar = unescape("Holen Sie sich jetzt die kostenlose MSN-Toolbar f%FCr Ihren Browser:");
locale.usage = unescape("Dieses Gadget sendet anonyme Nutzerdaten %FCber die betrachteten Inhalte von MSN.de. Es werden keinerlei zus%E4tzliche oder personenbezogene Daten gesendet.");

locale.flyout = {}
locale.flyout.no_description = "Keine Beschreibung verf&uuml;gbar.";
locale.flyout.read_more = "Mehr lesen auf MSN";
locale.flyout.see_more = "Video auf MSN";

locale.news = {};
locale.news.error0 = unescape("Dieser Kanal ist im Moment leider nicht erreichbar. Bitte versuchen Sie es sp%E4ter erneut.");
locale.news.error12007 = unescape("Es konnte keine Verbindung mit MSN hergestellt werden.");
locale.news.error12029 = unescape("Es konnte keine Verbindung mit dem Internet hergestellt werden.");
locale.news.errorDefault = unescape("Bei dem Versuch MSN zu kontaktieren ist ein Fehler aufgetreten.");
locale.news.readmore = "Mehr auf MSN";
locale.news.options_close = unescape("%DCbernehmen");

locale.searchbar = {};
locale.searchbar.search_hdr = 'Bing Suche';
locale.searchbar.srch_label = "Search by";

locale.categories = new Array(
        new Array("Nachrichten","http://news.de.msn.com/?ocid="+ocid, 100),
        new Array("Stars","http://unterhaltung.de.msn.com/?ocid="+ocid, 200),
        new Array("Lifestyle","http://lifestyle.de.msn.com/?ocid="+ocid, 300),
        new Array("Auto","http://lifestyle.de.msn.com/?ocid="+ocid, 400),
        new Array("Computer","http://tech.de.msn.com/?ocid="+ocid, 500),
        new Array("Fussball","http://sport.msn.de/fussball/startseite.html?ocid="+ocid, 600),
        new Array("Sport","http://sport.de.msn.com/?ocid="+ocid, 700),
        new Array("Money","http://money.de.msn.com/?ocid="+ocid, 800),
        new Array("Video","http://money.de.msn.com/?ocid="+ocid, 900),
        new Array("Suchtrends","http://unterhaltung.de.msn.com/suchtrends?ocid="+ocid, 1000));
         
locale.categories_docked = new Array(
        new Array("Nachrichten",""),
        new Array("Video",""),
        new Array("Stars",""),
        new Array("Lifestyle",""),
        new Array("Auto",""),
        new Array("Computer",""),
        new Array("Fussball",""),
        new Array("Sport",""));

locale.subcats = new Array( 
                            [
                                ["Top-Nachrichten", "http://news.de.msn.com/rss_newshome.aspx", false], 
                                ["Panorama","http://news.de.msn.com/rss_newsheadlines_panorama.aspx", false],
                                ["Politik","http://news.de.msn.com/rss_newsheadlines_politik.aspx", false],
                                ["Wirtschaft","http://news.de.msn.com/rss_newsheadlines_wirtschaft.aspx", false],
                                ["Video","http://partner.de.msn.com/msntoolbar/video-news.aspx", true],
                                ["Wetter","http://news.de.msn.com/rss_news2weather1.aspx", false]
                             ],
                            [ 
                                ["Star News","http://unterhaltung.de.msn.com/rss/rss_star_news.aspx", false],
                                ["Promi Zitate","http://unterhaltung.de.msn.com/msntoolbar/starzitate.aspx", false],
                                ["Musik News","http://unterhaltung.de.msn.com/rss/rss_musik_news.aspx", false],
                                ["Talk of Fame","http://unterhaltung.de.msn.com/msntoolbar/talk-of-fame.aspx", false],
                                ["Video","http://partner.de.msn.com/msntoolbar/video-unterhaltung.aspx", true]
                            ],
                           
                            [
                                ["Gesundheit","http://lifestyle.de.msn.com/msntoolbar/gesundheit.aspx", false],
                                ["Beauty","http://beauty.lifestyle.msn.de/beauty/rss", false],
                                ["Leben","http://lifestyle.de.msn.com/msntoolbar/leben.aspx", false],
                                ["Liebe &amp; Dating","http://lifestyle.de.msn.com/msntoolbar/Liebe-und-Dating.aspx", false],
                                ["Mode","http://mode.lifestyle.msn.de/mode/rss", false],
                                ["Video","http://partner.de.msn.com/msntoolbar/video-lifestyle.aspx", true]
                             ],
                                  
                            [
                                ["Nachrichten","http://auto.de.msn.com/rss_autonews.aspx", false],
                                ["Tests","http://auto.de.msn.com/rss_autotestberichte.aspx", false],
                                ["Video","http://partner.de.msn.com/msntoolbar/video-auto.aspx", true],
                             ],
                      
                            [
                                ["Sicherheit","http://tech.de.msn.com/msntoolbar/sicherheit.aspx", false],
                                ["Downloads","http://tech.de.msn.com/msntoolbar/downloads.aspx", false],
                                ["Test","http://tech.de.msn.com/msntoolbar/kaufberatung.aspx", false],
                                ["Ratgeber &amp; Praxis","http://tech.de.msn.com/msntoolbar/ratgeber.aspx", false],
                                ["Spiele","http://tech.de.msn.com/msntoolbar/spiele.aspx", false],
                                ["Video","http://partner.de.msn.com/msntoolbar/video-computer-technik.aspx", true]
                             ],
                                   
                            [
                                ["Fussball","http://sport.msn.de/rss/news/fussball", false],
                                ["Bundesliga","http://sport.msn.de/rss/news/bundesliga", false],
                                ["Bundesliga 2","http://sport.msn.de/rss/news/2bundesliga", false],
                                ["Regionalliga","http://sport.msn.de/rss/news/regionalliga", false],
                                ["DFB-Pokal","http://sport.msn.de/rss/news/dfbpokal", false],
                                ["Nationalelf","http://sport.msn.de/rss/news/nationalelf", false],
                                ["Int. Fuball","http://sport.msn.de/rss/news/intfussball", false],
                                ["Champions League","http://sport.msn.de/rss/news/clnews", false],
                                ["UEFA Cup","http://sport.msn.de/rss/news/uefacup", false],
                                ["WM News","http://sport.msn.de/rss/news/wm", false],
                                ["EM News","http://sport.msn.de/rss/news/em", false],
                                ["Oberliga News","http://sport.msn.de/rss/news/oberliga", false],
                                [unescape("Frauenfu%DFball"),"http://sport.msn.de/rss/news/frauenfussball", false],
                                [unescape("Jugendfu%DFball"),"http://sport.msn.de/rss/news/jugendfussball", false]
                             ],
                                  
                            [
                                ["Formel1","http://sport.de.msn.com/msntoolbar/formel1.aspx", false],
                                ["DTM","http://sport.de.msn.com/msntoolbar/DTM.aspx", false],
                                ["Basketball","http://sport.msn.de/rss/news/basketball", false],
                                ["Eishockey","http://sport.msn.de/rss/news/eishockey", false],
                                ["Handball","http://sport.msn.de/rss/news/handball", false],
                                ["Radsport","http://sport.msn.de/rss/news/radsport", false],
                                ["Tennis","http://sport.msn.de/rss/news/tennis", false],
                                ["Motorrad","http://sport.de.msn.com/msntoolbar/motorrad.aspx", false],
                                ["Rally","http://sport.de.msn.com/msntoolbar/rallye.aspx", false],
                                ["Mehr Sport","http://sport.msn.de/rss/news/mehrsport", false],
                                ["Video","http://partner.de.msn.com/msntoolbar/video-sport.aspx", true]
                             ],
                                  
                            [
                                ["Top-Nachrichten","http://money.de.msn.com/rss_topthemen.aspx", false],
                                [unescape("B%F6rsen News"),"http://money.de.msn.com/rss_aktien.aspx", false],
                                ["Immobilien News","http://money.de.msn.com/rss_immobilien.aspx", false],
                                ["Karriere","http://money.de.msn.com/msntoolbar/karriere.aspx", false],
                                ["Video","http://partner.de.msn.com/msntoolbar/video-money.aspx", true]
                             ],
                                   
                            [   
                                ["Neueste Videos","http://partner.de.msn.com/msntoolbar/video-latest.aspx", true],
                                ["Unterhaltung","http://partner.de.msn.com/msntoolbar/video-unterhaltung.aspx", true],
                                ["Uservideos","http://partner.de.msn.com/msntoolbar/video-user.aspx", true]
                             ],
                                    
                            [
                                ["Suchtrends","http://unterhaltung.de.msn.com/suchtrends/msntoolbar.aspx", false],
                                ["Star-Suche","http://unterhaltung.de.msn.com/msntoolbar/peoplesearch.aspx", false],
                                ["Top-Suche","http://unterhaltung.de.msn.com/suchtrends/msntoolbar.aspx", false]
                             ] );
                             
locale.searchcategories = new Array( ["Web", "http://www.bing.com/search?go=&form=degad&scope=web&filt=all&q="],
                                     ["Videos", "http://www.bing.com/videos/search?go=&form=degad&scope=video&filt=all&q="],
                                     ["Bilder", "http://www.bing.com/images/search?go=&form=degad&scope=images&filt=all&q="],
                                     ["Maps", "http://www.bing.com/maps/?mkt=de-de&go=SearchMaps&form=degad&q="],
                                     ["xRank", "http://www.bing.com/xrank/results.aspx?form=degad&q="]);
                                     
locale.searchcategories_docked = new Array( ["Web", "http://www.bing.com/search?go=&form=degad&scope=web&filt=all&q="],
                                 ["Videos", "http://www.bing.com/videos/search?go=&form=degad&scope=video&filt=all&q="],
                                 ["Bilder", "http://www.bing.com/images/search?go=&form=degad&scope=images&filt=all&q="]);

locale.weather = {};
locale.weather.std_degree = "C";
locale.weather.culture = "de-DE";
locale.weather.name = "Wetter";
locale.weather.changeLocation = "[ Standort wechseln ]";
locale.weather.changeLocation_docked = "Ort wechseln";
locale.weather.close = unescape("[ Ansicht schlie%DFen ]");
locale.weather.loc_asOf = "Um ";
locale.weather.loc_in = "in";
locale.weather.feelslike = unescape("Gef%FChlte Temperatur");
locale.weather.notAvailable = "Keine Daten";
locale.weather.noLocation = unescape("Kein Ort gew%E4hlt.");
locale.weather.searchForLoc = "Stadt oder PLZ eingeben";
locale.weather.cancelSearchLoc = "[ abbrechen ]";
locale.weather.cleaLocHistory = unescape("[ Standorte l%F6schen ]");
locale.weather.startSearch = "Suche";
locale.weather.loading = "Wetter wird geladen...";
locale.weather.flyout_headline = unescape("Die Wettervorhersage f%FCr ");
locale.weather.flyout_btn = "10-Tage Vorschau";
locale.weather.searching = unescape("Suche l%E4uft");

locale.weather.days = new Array("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag");

//Returns the keyboard-specific characters
locale.keyboard = function(keyCode){
    switch(keyCode){
        case 20: return unescape("%3D");
        case 21: return unescape("%21");
        case 22: return unescape("%22");        
        //case 23: return unescape("%3D");
        case 24: return unescape("%24");
        case 25: return unescape("%25");
        case 26: return unescape("%26");
        case 27: return unescape("%2F");
        case 28: return unescape("%28");
        case 29: return unescape("%29");
    
        case 186: return unescape("%FC");//ü
        case 188: return ",";
        case 189: return "-";
        case 190: return ".";
        case 192: return unescape("%F6");//oe
        case 219: return unescape("%DF");//ß
        case 222: return unescape("%E4");//ä
        
        default: return "";
    }
}

/** platformConnector.js
*
*   Provides the functionality for the gadget to run on different platforms
*   without changing the Sourcecode.
*
*   When the constructor is called it checks the availability of platform-specific
*   variables. Depending on the platform some methods of the PlatformConnector are
*   bound. The remaining methods are bound with the function "empty" which does
*   nothing and returns "false".
*
**/

var prefs;

function PlatformConnector(){

    //Bind the Sidebar-specific functions
    if(typeof(System) != "undefined"){
        PlatformConnector.prototype.saveSettings = saveSettingsVista;
        PlatformConnector.prototype.loadSettings = loadSettingsVista;
        PlatformConnector.prototype.isDocked = isDockedVista;
        PlatformConnector.prototype.beginTransition = beginTransitionVista;
        PlatformConnector.prototype.endTransition = endTransitionVista;
        PlatformConnector.prototype.onSettingsClosed = onSettingsClosedVista;
        PlatformConnector.prototype.flyoutShow = FlyoutShowVista;
        PlatformConnector.prototype.onUndock = onUndockVista;
        PlatformConnector.prototype.onDock = onDockVista;
        PlatformConnector.prototype.settingsUI = settingsUIVista;
        PlatformConnector.prototype.getData = getDataVista;
        PlatformConnector.prototype.getWeatherData = getWeatherDataVista;
        PlatformConnector.prototype.getWeatherSearch = getWeatherSearchVista;
        PlatformConnector.prototype.setBackgroundPNG = setBackgroundPNGVista;
        PlatformConnector.prototype.setImage = setImageVista;
        PlatformConnector.prototype.makePageView = makePageViewVista;
        PlatformConnector.prototype.setFlyoutFile = setFlyoutFileVista;
        PlatformConnector.prototype.onFlyoutShow = onFlyoutShowVista;
        PlatformConnector.prototype.setDimensionsLarge = setDimensionsVista;
        
    //Bind the IGoogle-specific functions
    } else if(typeof(gadgets) != "undefined"){
        prefs = new _IG_Prefs();
        PlatformConnector.prototype.saveSettings = saveSettingsIGoogle;
        PlatformConnector.prototype.loadSettings = loadSettingsIGoogle;
        PlatformConnector.prototype.getData = getDataIGoogle;
        PlatformConnector.prototype.getWeatherData = getWeatherDataIGoogle;
        PlatformConnector.prototype.getWeatherSearch = getWeatherSearchIGoogle;
        PlatformConnector.prototype.setImage = setImageWeb;
        PlatformConnector.prototype.makePageView = makePageViewIGoogle;
        PlatformConnector.prototype.setDimensionsLarge = setDimensionsWeb;
    
    //Binds the Netvibes ("Universal Widgets API") specific functions    
    } else if(typeof(widget) != "undefined"){
        PlatformConnector.prototype.saveSettings = saveSettingsUWA;
        PlatformConnector.prototype.loadSettings = loadSettingsUWA;
        PlatformConnector.prototype.getData = getDataUWA;
        PlatformConnector.prototype.getWeatherData = getWeatherDataUWA;
        PlatformConnector.prototype.getWeatherSearch = getWeatherSearchUWA;
        PlatformConnector.prototype.setImage = setImageWeb;
        PlatformConnector.prototype.makePageView = makePageViewIGoogle;
        PlatformConnector.prototype.setDimensionsLarge = setDimensionsWeb;
    }
    
    //Check if some of the methods are not bound and bind them
    if(!PlatformConnector.prototype.saveSettings)
        PlatformConnector.prototype.saveSettings = empty;
    
    if(!PlatformConnector.prototype.loadSettings)
        PlatformConnector.prototype.loadSettings = empty;
    
    if(!PlatformConnector.prototype.isDocked)  
        PlatformConnector.prototype.isDocked = empty;
        
    if(!PlatformConnector.prototype.getData)
        PlatformConnector.prototype.getData = empty;
    
    if(!PlatformConnector.prototype.beginTransition)
        PlatformConnector.prototype.beginTransition = empty;
    
    if(!PlatformConnector.prototype.endTransition)
        PlatformConnector.prototype.endTransition = empty;
    
    if(!PlatformConnector.prototype.onSettingsClosed)
        PlatformConnector.prototype.onSettingsClosed = empty;
    
    if(!PlatformConnector.prototype.flyoutShow)
        PlatformConnector.prototype.flyoutShow = empty;
        
    if(!PlatformConnector.prototype.onUndock)
        PlatformConnector.prototype.onUndock = empty;
    
    if(!PlatformConnector.prototype.onDock)
        PlatformConnector.prototype.onDock = empty;
    
    if(!PlatformConnector.prototype.settingsUI)
        PlatformConnector.prototype.settingsUI = empty;
        
    if(!PlatformConnector.prototype.getWeatherData)
        PlatformConnector.prototype.getWeatherData = empty;
        
    if(!PlatformConnector.prototype.getWeatherSearch)
        PlatformConnector.prototype.getWeatherSearch = empty;
        
    if(!PlatformConnector.prototype.setBackgroundPNG)
        PlatformConnector.prototype.setBackgroundPNG = empty;
        
    if(!PlatformConnector.prototype.setImage)
        PlatformConnector.prototype.setImage = empty;
        
    if(!PlatformConnector.prototype.makePageView)
        PlatformConnector.prototype.makePageView = empty;
        
    if(!PlatformConnector.prototype.setFlyoutFile)
        PlatformConnector.prototype.setFlyoutFile = empty;
        
    if(!PlatformConnector.prototype.onFlyoutShow)
        PlatformConnector.prototype.onFlyoutShow = empty;
        
    if(!PlatformConnector.prototype.setDimensionsLarge)
        PlatformConnector.prototype.setDimensionsLarge = empty;
    
};

//Dummy function, which is applied when the given functionality is not available
function empty(){
    return false;
}

/***************************************
            Vista version
***************************************/

function saveSettingsVista(name, value){
    System.Gadget.Settings.write(name, value);
}

function loadSettingsVista(name){
    return System.Gadget.Settings.read(name);
}

function isDockedVista(){
    return System.Gadget.docked;
}

function beginTransitionVista(){
    System.Gadget.beginTransition();
}

function endTransitionVista(timeTransition){
    System.Gadget.endTransition(System.Gadget.TransitionType.none, timeTransition);
}

function onSettingsClosedVista(funct){
    System.Gadget.onSettingsClosed = funct;
}

function onUndockVista(funct){
    System.Gadget.onUndock = funct;
}

function onDockVista(funct){
    System.Gadget.onDock = funct;
}

function FlyoutShowVista(){
    if(arguments.length == 1){
        if(System.Gadget.Flyout.show != arguments[0])
            System.Gadget.Flyout.show = arguments[0];
    }
    
    return System.Gadget.Flyout.show;
}

function settingsUIVista(document){
    System.Gadget.settingsUI = document;
}

function getDataVista(url){
    var rssObj = new ActiveXObject("Msxml2.XMLHTTP");
    rssObj.open("GET", url, true);
    rssObj.onreadystatechange = function() {
        if (rssObj.readyState === 4) {
            if (rssObj.status === 200) {
                var rssXML = rssObj.responseXML;
                News.processData(rssXML);
            } else {
                News.showError(rssObj.status);
            }
        } else {
        
        }
    }
    
    rssObj.send(null);
}

//Generates a pageview at our tracking-partner
function makePageViewVista(counter){

    var linkURL = MSNWidget.preview_link[counter];
    if(linkURL.indexOf('?') != -1)linkURL += "&ocid="+ocid_pv;
    else linkURL += "?ocid="+ocid_pv;
    
    if(document.getElementById("tracking") == null){
        var tag = document.createElement("script");
        tag.type="text/javascript";
        tag.src = "http://estj.msn.com/br/om/js/s_code.js";
        tag.id = 'tracking';
        document.body.appendChild(tag);
    }
    
    var page = new ActiveXObject("Msxml2.XMLHTTP");
    page.open("GET", linkURL, true);
    page.onreadystatechange = function() {
        if(page.readyState == 4){
            if(page.status == 200){
                var response = page.responseText;
                
                var url = evalPageview(response, linkURL);
            
                var rssObj = new ActiveXObject("Msxml2.XMLHTTP");
                rssObj.open("GET", url, true);
                rssObj.onreadystatechange = function() {
                    if(rssObj.readyState == 2){
                    }
                }
                rssObj.send(null);                
            }
        }
    }
    page.send(null);
         
}

function getWeatherDataVista(url){
    var rssObj = new ActiveXObject("Msxml2.XMLHTTP");
    rssObj.open("GET", url, true);
    rssObj.onreadystatechange = function() {
        if (rssObj.readyState === 4) {
            if (rssObj.status === 200) {
                var rssXML = rssObj.responseXML;
                Weather.GetWeatherData(rssXML, "C");
                Weather.save();
                Weather.showSmallWeather();
                if(Weather.visible)
                    Weather.showWeather();
                else Weather.show(false);
                Weather.loading(false);
            } else {
                Weather.loading(false);
            }
        } else {
            Weather.loading(false);
        }
    }
    rssObj.send(null);
}

function getWeatherSearchVista(url){
    var rssObj = new ActiveXObject("Msxml2.XMLHTTP");
    rssObj.open("GET", url, true);
    rssObj.onreadystatechange = function() {
        if (rssObj.readyState === 4) {
            if (rssObj.status === 200) {
                Weather.loading(false);
                var rssXML = rssObj.responseXML;
                Weather.getLocationData(rssXML);
                //Weather.showWeather();
            } else {
                Weather.loading(false);
            }
        } else {
            
        }
    }
    rssObj.ontimeout
    rssObj.send(null);
}

function setBackgroundPNGVista(src){ 
   System.Gadget.background = src;
}

function setImageVista(url, counter){
    // Retrieve a reference to the plug-in.
    var slPlugin = MSNWidget.root.getHost();
    var downloader = slPlugin.createObject("downloader");

    downloader.addEventListener("completed", function(sender){GUI.Content.Events.downloader(sender, counter)});
    downloader.addEventListener("DownloadFailed", function(sender){
    MSNWidget.root.findName("news_img_"+counter).Source = config.image_str + "default/"+News.getCategory()+".jpg";
    MSNWidget.root.findName("news_img_refl_"+counter).Source = config.image_str + "default/"+News.getCategory()+".jpg";

        GUI.Content.Events.downloader(null, counter);
    });
    
    downloader.open("GET", url);
    downloader.send();
}

function setFlyoutFileVista(url){
    System.Gadget.Flyout.file = url;
}

function onFlyoutShowVista(fnct){
    System.Gadget.Flyout.onShow = fnct;
}

function setDimensionsVista(){
    with (document.body.style) {
        width = 385;
        height = 280;
    }
    document.getElementById("MSNSilverlight").style.width = "385px";
    document.getElementById("MSNSilverlight").style.height = "280px";
}

/**************************************************
            IGoogle Version 
**************************************************/
function saveSettingsIGoogle(name, value){
    prefs.set(name, value);
}

function loadSettingsIGoogle(name, type){
    var result;
    switch(type){
      case "String": result = prefs.getString(name);break;
      
      case "bool": result = prefs.getBool(name);break;
      
      default: result = prefs.getString(name);break;
    }

    if(result == "")return false;
    else return result;
}

function getDataIGoogle(url){
        
    var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM;
    gadgets.io.makeRequest(url, function(response) {
            News.processData(response.data);
        }, params);
}

function getWeatherDataIGoogle(url){

    var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM;
    gadgets.io.makeRequest(url, function(response) {
        Weather.GetWeatherData(response.data, "C");
        Weather.save();
        Weather.showWeather();
        Weather.showSmallWeather();
        Weather.loading(false);
      }, params);
}

function getWeatherSearchIGoogle(url){

    var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM;
    gadgets.io.makeRequest(url, function(response) {
        Weather.getLocationData(response.data);
        Weather.showWeather();
      }, params);
}

function setImageIGoogle(link, counter){
    MSNWidget.root.findName("news_img_"+counter).Source = link;
    MSNWidget.root.findName("news_img_refl_"+counter).Source = link;
    GUI.Content.Events.downloader(null, counter);
}

function makePageViewIGoogle(counter){

    var linkURL = MSNWidget.preview_link[counter];
    if(linkURL.indexOf('?') != -1)linkURL += "&ocid="+ocid_pv;
    else linkURL += "?ocid="+ocid_pv;
    
    if(document.getElementById("tracking") == null){
        var tag = document.createElement("script");
        tag.type="text/javascript";
        tag.src = "http://estj.msn.com/br/om/js/s_code.js";
        tag.id = 'tracking';
        document.body.appendChild(tag);
    }
    
    var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
    gadgets.io.makeRequest(linkURL, function(reponse, linkURL){igoogleCallback(reponse, linkURL);}, params);         
}

//helperfunction for the google-specific ajax calls
function igoogleCallback(response, linkURL){

    var url = evalPageview(response.text, linkURL);

    var params = {};
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
    gadgets.io.makeRequest(url, null, params);                
}

function setDimensionsWeb(){
    document.getElementById("MSNSilverlight").style.width = "385px";
    document.getElementById("MSNSilverlight").style.height = "280px";
}


/**************************************************
            IGoogle Version 
**************************************************/
function saveSettingsUWA(name, value){
    widget.setValue(name, value);
}

function loadSettingsUWA(name, type){
    var result;
    switch(type){
      case "String": result = widget.getValue(name);break;
      
      case "bool": result = widget.getBool(name);break;
      
      default: result = widget.getValue(name);break;
    }

    if(result == "" || result == null)return false;
    else return result;
}

function getDataUWA(url){

    UWA.Data.request(
        url,
        {
            method: 'get',
            proxy: 'ajax',
            type: 'xml',
            cache: 3600,
            onComplete: News.processData
        });
}

function getWeatherDataUWA(url){
      
      UWA.Data.request(
        url,
        {
            method: 'get',
            proxy: 'ajax',
            type: 'xml',
            cache: 3600,
            onComplete: function(response) {
                Weather.GetWeatherData(response, "C");
                Weather.save();
                Weather.showWeather();
                Weather.showSmallWeather();
                Weather.loading(false);
              }
        });
}

function getWeatherSearchUWA(url){

      UWA.Data.request(
        url,
        {
            method: 'get',
            proxy: 'ajax',
            type: 'xml',
            cache: 3600,
            onComplete: function(response) {
                Weather.getLocationData(response.data);
                Weather.showWeather();
              }
        });  
}

function makePageViewUWA(counter){

    var linkURL = MSNWidget.preview_link[counter];
    if(linkURL.indexOf('?') != -1)linkURL += "&ocid="+ocid_pv;
    else linkURL += "?ocid="+ocid_pv;
    
    if(document.getElementById("tracking") == null){
        var tag = document.createElement("script");
        tag.type="text/javascript";
        tag.src = "http://estj.msn.com/br/om/js/s_code.js";
        tag.id = 'tracking';
        document.body.appendChild(tag);
    }
    
    UWA.Data.request(
        linkURL,
        {
            method: 'get',
            proxy: 'ajax',
            type: 'text',
            cache: 3600,
            onComplete: function(response, linkURL){UWACallback(response, linkURL);}
        });           
}

//helperfunction for the google-specific ajax calls
function UWACallback(response, linkURL){

    var url = evalPageview(response, linkURL);

    UWA.Data.request(
        url,
        {
            method: 'get',
            proxy: 'ajax',
            type: 'xml',
            cache: 3600,
            onComplete: null
        });                 
}



/*********************************************
*       GENERIC FUNCTIONS
*********************************************/
function setDimensionsWeb(){
    document.getElementById("MSNSilverlight").style.width = "385px";
    document.getElementById("MSNSilverlight").style.height = "280px";
}

function setImageWeb(link, counter){
    MSNWidget.root.findName("news_img_"+counter).Source = link;
    MSNWidget.root.findName("news_img_refl_"+counter).Source = link;
    GUI.Content.Events.downloader(null, counter);
}

function evalPageview(response, linkURL){
    //Limit the response to the tracking-div
    response = '<div ' + response.substring(response.indexOf('id="omni"'));
    response = response.substring(0, response.indexOf('</div>')+6);
    
    //Read out the s_account
    response = response.substring(response.indexOf("s_account")+11) ;
    var s_account = response.substring(0, response.indexOf(";")-1);
    
    //Read out the configurations
    var config_js = response.substring(response.indexOf("s.linkInternal"));
    config_js = config_js.substring(0, config_js.indexOf("s_code=s.t();")+14);
    
    
    eval(config_js);
    s.prop50 = linkURL;
    var s_code = s.t();
    var url = s_code.substring(s_code.indexOf('src="')+5);
    url = url.substring(0, url.indexOf('"'));
    
    //Rework the parameter "g"
    var g = url.substring(url.indexOf("&g=")+3);
    g = g.substring(g.indexOf("&"));
    url = url.substring(0, url.indexOf("&g=")+3) + escape(linkURL) + g;
    
    //Rework the parameter "c29"
    var c29 = url.substring(url.indexOf("&c29=")+5);
    c29 = c29.substring(c29.indexOf("&"));
    var shortUrl = linkURL.substring(0, linkURL.indexOf("?"));
    url = url.substring(0, url.indexOf("&c29=")+5) + shortUrl + c29;
    
    return url;
}
//Global variable, used to store a reference to the Flyout-Silverlight-object
var flyoutSL = null;

function delegate(o,m){
    return function(){
        return m.apply(o,arguments)
    }
}

if (!window.UntitledProject1)
MSNWidget = {};

MSNWidget.Page = function()
{

}

MSNWidget.Page.prototype =
{
    handleLoad: function(control, userContext, rootElement) {
        
        document.body.style.width = 135;
        
        MSNWidget.platformConnector = new PlatformConnector();
        MSNWidget.platformConnector.setFlyoutFile("flyout.html");
        MSNWidget.platformConnector.onFlyoutShow(function() {
            if(Weather.visible)
                Flyout.showWeather();
            else
                Flyout.addContentToFlyout();
        });
    
        MSNWidget.platformConnector.onSettingsClosed(GUI.Bar.inkBar);
        MSNWidget.platformConnector.onUndock(GUI.undocked);
        MSNWidget.platformConnector.onDock(GUI.docked);
        MSNWidget.platformConnector.settingsUI("settings.html");
        var result = MSNWidget.platformConnector.loadSettings("SettingsPresent", "bool");
        var save_str = "";
        if (result == (false || "") ) {
            MSNWidget.platformConnector.saveSettings("bgColor", 0);
            
            for(i = 0; i < locale.categories.length; i++){
                save_str += i + "-";
            }
            save_str = save_str.substring(0, save_str.length-1);
            MSNWidget.platformConnector.saveSettings("categories", save_str);
        }

        MSNWidget.control = control;
        MSNWidget.rootElement = rootElement;

        MSNWidget.root = rootElement;
        MSNWidget.flyout = false;
        MSNWidget.categories = new Array();
                
        //Die Kategorien in der richtigen Reihenfolge einlesen
        if(MSNWidget.platformConnector.loadSettings("categories") == false)
            cats = save_str.split("-");
        else
            cats = MSNWidget.platformConnector.loadSettings("categories").split("-");
            
        for(i = 0; i < cats.length; i++){
            MSNWidget.categories.push(locale.categories[parseInt(cats[i])]);
        }
        
        MSNWidget.preview = new Array();
        MSNWidget.preview_img = new Array();
        MSNWidget.preview_date = new Array();
        MSNWidget.preview_title = new Array();
        MSNWidget.preview_link = new Array();
        MSNWidget.news = 0;
        MSNWidget.newsCat = 101;
        MSNWidget.downloaded_images = 0;
        MSNWidget.total_images = 0;
    
        GUI.update();
        
        WeatherSearchBar_init();
        Scrollbar_Init();
        Weather.init();
        rootElement.findName("SearchBar_hidden").Focus();
        
        MSNWidget.weatherSearchBar = new WeatherSearchBar();
        MSNWidget.weatherSearchBar.init(MSNWidget.root);        
                
        MSNWidget.token_me_l = null;
        MSNWidget.token_me_r = null;
        MSNWidget.token_ml_l = null;
        MSNWidget.token_ml_r = null;
        MSNWidget.token_md_l = null;
        MSNWidget.token_md_r = null;
        MSNWidget.token_flyout = null;
        
        rootElement.addEventListener("LostFocus", GUI.handleLostFocus);
        rootElement.addEventListener("MouseMove", GUI.Bar.Events.handleMouseMoveRoot);
        rootElement.addEventListener("MouseLeave", GUI.Content.Events.handleMouseLeave);
        rootElement.findName("Bar").addEventListener("MouseMove", GUI.Bar.Events.handleMouseMoveBar);
        rootElement.findName("Bar").addEventListener("MouseLeave", GUI.Bar.Events.handleMouseLeaveBar);
        rootElement.findName("More").addEventListener("MouseMove", GUI.Bar.Events.handleMouseMoveBar);
        rootElement.findName("More").addEventListener("MouseLeave", GUI.Bar.Events.handleMouseLeaveBar);
                
        if (MSNWidget.platformConnector.loadSettings("SettingsPresent", "bool"))
            MSNWidget.newsCat = parseInt(MSNWidget.platformConnector.loadSettings("newsCat"));
                  
        GUI.Bar.addEvents(rootElement.findName("MSN-Startseite"));
        GUI.Bar.addEvents(rootElement.findName("subcat_text"));
        
        rootElement.findName("subcat_main_left_btn").addEventListener("MouseLeftButtonDown", GUI.Bar.switchMainCat);
        rootElement.findName("subcat_main_right_btn").addEventListener("MouseLeftButtonDown", GUI.Bar.switchMainCat);

        GUI.buildSubcats(rootElement, MSNWidget.newsCat);
        
        SearchBar.init();
        
        MSNWidget.rootElement.addEventListener("MouseLeftButtonDown", GUI.looseFocus);
        rootElement.findName("SearchBar_Options").addEventListener("MouseLeftButtonDown", GUI.showOptions);
        rootElement.findName("SearchBar_Usage").addEventListener("MouseLeftButtonDown", GUI.showUsage);
        rootElement.findName("SearchBar_Download").addEventListener("MouseLeftButtonDown", GUI.showDownload);
        GUI.Bar.addEvents(rootElement.findName("Btn_MSN"));
        GUI.Bar.addEvents(rootElement.findName("Btn_More"));

                
        if(MSNWidget.platformConnector.isDocked())
            GUI.docked();
        else GUI.undocked();
            GUI.undocked();
        
        SearchBar.showButtons(!MSNWidget.platformConnector.isDocked());
        window.focus();
        
    }
    
}
var Weather = {};

Weather.srcID = 'msntoolbar';
Weather.url = 'http://weather.partners.msn.com/data.aspx?src='+Weather.srcID+'&culture='+locale.weather.culture+'&degreetype='+locale.weather.std_degree+'&wealocations=';
Weather.searchURL = 'http://weather.partners.msn.com/find.aspx?outputview=search&culture='+locale.weather.culture+'&src='+Weather.srcID+'&weasearchstr=';
Weather.forecastURL = 'http://wetter.msn.com/tenday.aspx?src='+Weather.srcID+'&OCID='+ocid+'&wealocations=';
Weather.mainURL = 'http://wetter.msn.com/?ocid='+ocid;
Weather.msnURL = "";
Weather.imagePath = config.weather_image_str;
Weather.locations = new Array();
Weather.locationCodes = new Array();
Weather.attribution = '';
Weather.degreetype = 'C';
Weather.visible = false;
Weather.locationVisible = false;
Weather.imagerelativeURL = '';
Weather.interval = null;

Weather.weatherXML = '';

Weather.current = {};
Weather.current.location = "";
Weather.current.temperature = 0;
Weather.current.latitude = 0;
Weather.current.skycode = 0;
Weather.current.skytext = '';
Weather.current.observationtime = 0;
Weather.current.timestamp = 0;
Weather.current.feelslike = 0;
Weather.current.humidity = 0;
Weather.current.windspeed = 0;
Weather.current.weatherIcon = {sunMoonImg:"", weatherImg:"",sky:"", sunMoonRotation:""};

Weather.forecast = new Array(5);
for(var i = 0; i < Weather.forecast.length; i++){
	Weather.forecast[i] = {};
	Weather.forecast[i].low = 0;
	Weather.forecast[i].high = 0;
	Weather.forecast[i].skycodeday = 0;
	Weather.forecast[i].skytextday = '';
	Weather.forecast[i].precip = 0;
	Weather.forecast[i].weatherIcon = {sunMoonImg:"sunMoon_19.png", weatherImg:"",sky:"Sky_Clear2", sunMoonRotation:""};
}

Weather.init = function(){

    Weather.scrollbar = new Scrollbar();
    Weather.scrollbar.init(MSNWidget.root);
    
    //At first, hide everything
    MSNWidget.root.findName("current_large").Visibility = "Visible";
    MSNWidget.root.findName("current_small").Visibility = "Collapsed";

    var obj_txt_change = MSNWidget.root.findName("Weather_ChangeLocation");
    obj_txt_change.addEventListener("MouseLeftButtonDown", Weather.click_ChangeLocation);
    obj_txt_change.Text = locale.weather.changeLocation;
    obj_txt_change["Canvas.Left"] = obj_txt_change.getParent().Width - obj_txt_change.ActualWidth - 15;
    
    var obj_txt_close = MSNWidget.root.findName("Weather_Close");
    obj_txt_close.addEventListener("MouseLeftButtonDown", Weather.click_ChangeLocation);
    obj_txt_close.Text = locale.weather.close;
    obj_txt_close["Canvas.Left"] = obj_txt_close.getParent().Width - obj_txt_close.ActualWidth - 15;
    
    var obj_txt_cancel = MSNWidget.root.findName("Weather_CancelChangeLocation");
    obj_txt_cancel.addEventListener("MouseLeftButtonDown", Weather.click_ChangeLocation);
    obj_txt_cancel.Text = locale.weather.cancelSearchLoc;
    obj_txt_cancel["Canvas.Left"] = obj_txt_cancel.getParent().Width - obj_txt_cancel.ActualWidth - 15;
    
    var obj_txt_clear = MSNWidget.root.findName("Weather_ClearChangeLocation");
    obj_txt_clear.addEventListener("MouseLeftButtonDown", Weather.click_ChangeLocation);
    obj_txt_clear.Text = locale.weather.cleaLocHistory;
    obj_txt_clear["Canvas.Left"] = obj_txt_clear.getParent().Width - obj_txt_clear.ActualWidth - obj_txt_cancel.ActualWidth - 15;
    
    var obj_txt_btn = MSNWidget.root.findName("txtLabel1");
    obj_txt_btn.Text = locale.weather.startSearch;
    obj_txt_btn["Canvas.Left"] = (obj_txt_btn.getParent().Width - obj_txt_btn.ActualWidth)/2;
    
    var obj_loading_txt = MSNWidget.root.findName("WeatherLoadingTxt");
    obj_loading_txt.Text = locale.weather.loading;
    obj_loading_txt["Canvas.Left"] = (MSNWidget.root.findName("Content").Width / 2) - (obj_loading_txt.ActualWidth / 2);
    obj_loading_txt["Canvas.Top"] = (MSNWidget.root.findName("Content").Height / 2) - (obj_loading_txt.ActualHeight / 2);
    
    MSNWidget.root.findName("Sky_Clear1").Source = Weather.imagePath +"sky_Clear.png";
    MSNWidget.root.findName("Sky_Cloudy").Source = Weather.imagePath +"sky_Cloudy.png";
    MSNWidget.root.findName("Sky_Clear2").Source = Weather.imagePath +"sky_Clear.png";
    MSNWidget.root.findName("Sky_Stars").Source = Weather.imagePath +"Sky_Stars.png";
    
    MSNWidget.root.findName("Sky_Clear1_small").Source = Weather.imagePath +"sky_Clear.png";
    MSNWidget.root.findName("Sky_Cloudy_small").Source = Weather.imagePath +"sky_Cloudy.png";
    MSNWidget.root.findName("Sky_Clear2_small").Source = Weather.imagePath +"sky_Clear.png";
    MSNWidget.root.findName("Sky_Stars_small").Source = Weather.imagePath +"Sky_Stars.png";
    
    MSNWidget.root.findName("Shadow_Menu2").Source = Weather.imagePath +"shadow_Menu.png";
    MSNWidget.root.findName("Shadow_Menu3").Source = Weather.imagePath +"shadow_Menu.png";
    MSNWidget.root.findName("Shadow_Menu1").Source = Weather.imagePath +"shadow_Menu.png";
    
    
    MSNWidget.root.findName("smallWeather").addEventListener("MouseLeftButtonDown", GUI.Bar.Events.handleMouseUp );
    MSNWidget.root.findName("smallWeather").addEventListener("MouseEnter", GUI.Bar.Events.handleMouseIn );
    MSNWidget.root.findName("smallWeather").addEventListener("MouseLeave", GUI.Bar.Events.handleMouseOut );
    MSNWidget.root.findName("Forecast_Canvas").addEventListener("MouseLeftButtonDown", Weather.openForecast);
    MSNWidget.root.findName("current_large").addEventListener("MouseLeftButtonDown", Weather.openForecast);
    MSNWidget.root.findName("current_small").addEventListener("MouseLeftButtonDown", Weather.showFlyout);
    
    //Read all the locations from the Settings
    var locations = MSNWidget.platformConnector.loadSettings("locations");
    var locationcodes = MSNWidget.platformConnector.loadSettings("locationcodes");
    if(locations != false){
        var locationsArray = locations.split("--");
        var locationCodesArray = locationcodes.split("--");
        for(var x = 0; x < locationsArray.length; x++){
            if(locationsArray[x] != ""){
                this.locations.push(locationsArray[x]);
                if(x >= locationCodesArray.length || locationCodesArray[x] == ""){
                        Weather.locations.pop();
                        break;
                    }
                this.locationCodes.push(locationCodesArray[x]);
            }
        }
    }
    
    this.resize();
    if(Weather.locationCodes.length > 0)
        Weather.send(Weather.locationCodes[0]);
    else {
        Weather.locationCodes.push(config.weather.defaultCode);
        Weather.locations.push(config.weather.defaultName);
        Weather.send(Weather.locationCodes[0]);
    }
    
    //Set the timer for refreshing the weather
    //Weather.refresh();
}

Weather.save = function(){
    
    var loc_str = "";
    var loc_code_str = "";
    for(var i = 0; i < Weather.locations.length; i++){
        loc_str += Weather.locations[i] + "--";
        loc_code_str += Weather.locationCodes[i] + "--";
    }
    
    loc_str = loc_str.substring(0, loc_str.length -2);
    loc_code_str = loc_code_str.substring(0, loc_code_str.length -2);
    
    MSNWidget.platformConnector.saveSettings("locationcodes", loc_code_str);
    MSNWidget.platformConnector.saveSettings("locations", loc_str);
}

Weather.openForecast = function(sender, eventArgs){
    
    var url = "";
    if(Weather.locationCodes.length == 0){
        url = Weather.mainURL;
    } else {
        url = Weather.forecastURL + Weather.locationCodes[0];
    }
    
    window.open(url);
}

Weather.showSmallWeather = function(){
    
    if(arguments.length == 1 && !arguments[0])
        MSNWidget.root.findName("smallWeather").Visibility = "Collapsed";
    else 
        MSNWidget.root.findName("smallWeather").Visibility = "Visible";
    
    if(MSNWidget.platformConnector.isDocked())
        MSNWidget.root.findName("smallWeather_Btn").Visibility = "Collapsed";
    else MSNWidget.root.findName("smallWeather_Btn").Visibility = "Visible";

    var img_sunMoon = MSNWidget.root.findName("smallSunMoonImg");
    if(Weather.current.weatherIcon.sunMoonImg != "")
        img_sunMoon.Source = Weather.imagePath + Weather.current.weatherIcon.sunMoonImg;
    else img_sunMoon.Source = "";
    
    var img_Weather = MSNWidget.root.findName("smallWeatherImg");
    if(Weather.current.weatherIcon.weatherImg != "")
        img_Weather.Source = Weather.imagePath + Weather.current.weatherIcon.weatherImg;
    else img_Weather.Source = "";
    
    var temperature = MSNWidget.root.findName("smallTemperature");
    if(Weather.current.temperature != "")
        temperature.Text = Weather.current.temperature +unescape("%B0")+Weather.degreetype;
    else temperature.Text = "";
    
}

Weather.resize = function(){
    var page = document.getElementById("MSNSilverlight");
    MSNWidget.root.findName("LocationSelection").Width = page.offsetWidth;
    MSNWidget.root.findName("LocationSelectionBg").Width = page.offsetWidth - 20;
    MSNWidget.root.findName("WeatherSearchBox").Width = page.offsetWidth - 20;
    
    var obj_chng = MSNWidget.root.findName("Weather_ChangeLocation");
    obj_chng["Canvas.Left"] = obj_chng.getParent().Width - obj_chng.ActualWidth - 15;
    
    var obj_close = MSNWidget.root.findName("Weather_Close");
    if(MSNWidget.platformConnector.isDocked())
        obj_close.Text = "[x]";
    else obj_close.Text = locale.weather.close;
    obj_close["Canvas.Left"] = (MSNWidget.platformConnector.isDocked()) ? 115 : obj_chng["Canvas.Left"] - obj_close.ActualWidth - 15;
    
    if(MSNWidget.platformConnector.isDocked()){
            GUI.Bar.checkArrows(News.getCategoryIndex());
        }
    
    var obj_locBtn = MSNWidget.root.findName("cnvWeatherLocation");
    obj_locBtn["Canvas.Left"] = (page.offsetWidth - 20) - obj_locBtn.Width;
    MSNWidget.root.findName("cnvScroll1").Width = MSNWidget.root.findName("LocationSelectionBg").Width;
    MSNWidget.root.findName("cnvScroll2")["Canvas.Left"] = MSNWidget.root.findName("LocationSelectionBg").Width - 20;
    
    var root = MSNWidget.root;
    var docked = MSNWidget.platformConnector.isDocked();
    
    var obj_loading_txt = MSNWidget.root.findName("WeatherLoadingTxt");
    obj_loading_txt["Canvas.Left"] = (MSNWidget.root.findName("Content").Width / 2) - (obj_loading_txt.ActualWidth / 2);
    obj_loading_txt["Canvas.Top"] = (MSNWidget.root.findName("Content").Height / 2) - (obj_loading_txt.ActualHeight / 2);
    
    root.findName("Weather")["Canvas.Top"] = (docked) ? -30 : -15;
    root.findName("Current_SunMoonIcon").Width = (docked) ? 150 : 180;
    root.findName("Current_SunMoonIcon").Height = (docked) ? 150 : 180;
    root.findName("Current_WeatherIcon").Width = (docked) ? 150 : 180;
    root.findName("Current_WeatherIcon").Height = (docked) ? 150 : 180;
    
}

//Gets the new weather-data repeatedly
Weather.refresh = function(){
    if(Weather.interval == null)
        Weather.interval = window.setInterval("Weather.refresh()", config.weather.refreshTime * 60 * 1000);
    else {
        if(Weather.locationCodes.length == 0 || Weather.locationVisible)
            return;
        
        Weather.send(Weather.locationCodes[0]);
    }
}

Weather.click_ChangeLocation = function(sender, mouseEventArgs){ 
    var obj = (MSNWidget.platformConnector.isDocked()) ? flyoutSL : MSNWidget.root;
    switch(sender.Name){
    
        case "Weather_ChangeLocation":
            Weather.locationVisible = true;
            obj.findName("Weather_ClearChangeLocation").Opacity = 1;
            obj.findName("LocationSelection").Opacity = 1;
            obj.findName("Weather_ClearChangeLocation").Visibility = "Visible";
            obj.findName("LocationSelection").Visibility = "Visible";
            obj.findName("Weather2Location").Begin();
            Weather.showLocationList();
            break;
            
        case "Weather_CancelChangeLocation":
            Weather.locationVisible = false;
            SearchBar.root.visibility = "Visible";
            MSNWidget.root.findName("WeatherDisplay").Visibility = "Visible";
            obj.findName("Location2Weather").Begin();
            Weather.clearLocationList();
            break;
            
        case "Weather_ClearChangeLocation":
            Weather.locationVisible = false;
            Weather.clearLocationList();
            Weather.clearLocations();
            Weather.save();
            SearchBar.root.visibility = "Visible";
            obj.findName("Location2Weather").Begin();
            break;
            
        case "Weather_Close":
            Weather.show(false);
            break;
    }
}

Weather.send = function(locationCode){
    if(this.locations.length == 0)return;
    
    Weather.loading(true);
    Weather.clearWeather();
    
    var url = Weather.url + locationCode;
    
    MSNWidget.platformConnector.getWeatherData(url);

}

Weather.search = function(searchstring){
    Weather.loading(true);
    var url = Weather.searchURL + encodeURIComponent(searchstring);
    MSNWidget.platformConnector.getWeatherSearch(url);
}

Weather.hideAllDay = function(){
    MSNWidget.root.findName("Sky_Day_Blue").Visibility = "Collapsed";
    MSNWidget.root.findName("Sky_Day_Grey").Visibility = "Collapsed";
    MSNWidget.root.findName("Sky_Day_Dust").Visibility = "Collapsed";
    MSNWidget.root.findName("Sky_Night").Visibility = "Collapsed";
    
    MSNWidget.root.findName("Sky_Day_Blue_small").Visibility = "Collapsed";
    MSNWidget.root.findName("Sky_Day_Grey_small").Visibility = "Collapsed";
    MSNWidget.root.findName("Sky_Day_Dust_small").Visibility = "Collapsed";
    MSNWidget.root.findName("Sky_Night_small").Visibility = "Collapsed";
}

function WeatherCollapse(sender, eventArgs){
    MSNWidget.root.findName("Weather").Visibility = "Collapsed";
}

/**
*   Show or hide the main weather-view
*/
Weather.show = function(show){
    SearchBar.showButtons(!show);
        
    Weather.showSmallWeather();
    if(show){
        if(Weather.visible)return;
        else Weather.visible = true;
                
        MSNWidget.root.findName("Weather").Opacity = 0;
        MSNWidget.root.findName("Weather").Visibility = "Visible";
        
        MSNWidget.root.findName("News2Weather").begin();
        Weather.showWeather();
    } else {
        if(!Weather.visible)return;
        else Weather.visible = false;
        
        MSNWidget.root.findName("NewsItemsContainer").Opacity = 0;
        MSNWidget.root.findName("Subcat_Scroll").Opacity = 0;
        MSNWidget.root.findName("SubCats").Opacity = 0;
        MSNWidget.root.findName("NewsItemsContainer").Visibility = "Visible";
        MSNWidget.root.findName("Subcat_Scroll").Visibility = "Visible";
        MSNWidget.root.findName("SubCats").Visibility = "Visible";
        
        if(MSNWidget.platformConnector.isDocked()){
            GUI.Bar.checkArrows(News.getCategoryIndex());
            MSNWidget.root.findName("subcat_text").Text = News.getCategory();
            MSNWidget.root.findName("innerSubcat")["Canvas.Left"] = (MSNWidget.root.findName("subcat").getParent().Width / 2) - (MSNWidget.root.findName("subcat_text").ActualWidth / 2);
            MSNWidget.root.findName("subcat_text_Hover").Width = MSNWidget.root.findName("subcat_text").ActualWidth;
            MSNWidget.root.findName("subcat_text_Hover").Height = MSNWidget.root.findName("subcat_text").ActualHeight;
            MSNWidget.platformConnector.flyoutShow(false);
        }
            
        if(MSNWidget.root.findName("NewsItems").children.count == 0)
            News.getNews(MSNWidget.newsCat);
        
        if(Weather.locationVisible)
            MSNWidget.root.findName("Location2Weather").Begin();
        SearchBar.root.visibility = "Visible";
        SearchBar.root.Opacity = 1;
        MSNWidget.root.findName("Weather2News").begin();
    }
}

// Calls the docked or undocked version of the weather
Weather.showWeather = function(){
    SearchBar.showButtons(false);
    Weather.hideAllDay();
    if(MSNWidget.platformConnector.isDocked()){
        MSNWidget.root.findName("current_small").Visibility = "Visible";
        MSNWidget.root.findName("current_large").Visibility = "Collapsed";
        if(Weather.locationVisible){
            SearchBar.root.Visibility = "Visible";
            MSNWidget.root.findName("Location2Weather").begin();
        }
        Weather.showDocked();
    } else {
        MSNWidget.root.findName("current_small").Visibility = "Collapsed";
        MSNWidget.root.findName("current_large").Visibility = "Visible";
        Weather.showUndocked();
    }
}

Weather.showDocked = function(){
    Weather.resize();
    Weather.showSmallWeather(false);
     MSNWidget.root.findName("subcat_text").Text = locale.weather.name;
     MSNWidget.root.findName("innerSubcat")["Canvas.Left"] = (MSNWidget.root.findName("subcat").getParent().Width / 2) - (MSNWidget.root.findName("subcat_text").ActualWidth / 2);
     MSNWidget.root.findName("subcat_text_Hover").Width = MSNWidget.root.findName("subcat_text").ActualWidth;
     MSNWidget.root.findName("subcat_text_Hover").Height = MSNWidget.root.findName("subcat_text").ActualHeight;
     
    //Hide Maincat-Arrows
    MSNWidget.root.findName("subcat_main_left_btn").Visibility = "Collapsed";
    MSNWidget.root.findName("subcat_main_right_btn").Visibility = "Collapsed";

    //Show current weather
    MSNWidget.root.findName("Current_Temp_small").Text = Weather.current.temperature +unescape("%B0")+Weather.degreetype; 
    MSNWidget.root.findName("Current_FeelsLike_Text_small").Text = locale.weather.feelslike;
    MSNWidget.root.findName("Current_FeelsLike_Temp_small").Text = Weather.current.feelslike +unescape("%B0")+Weather.degreetype;
    MSNWidget.root.findName("Current_Conditions_small").Text = Weather.current.skytext;    

    if(Weather.current.weatherIcon.sunMoonImg != "")
        MSNWidget.root.findName("Current_SunMoonIcon_small").Source = Weather.imagePath + Weather.current.weatherIcon.sunMoonImg;
    else MSNWidget.root.findName("Current_SunMoonIcon_small").Source = "";

    if(Weather.current.weatherIcon.weatherImg != "")
        MSNWidget.root.findName("Current_WeatherIcon_small").Source = Weather.imagePath + Weather.current.weatherIcon.weatherImg;
    else MSNWidget.root.findName("Current_WeatherIcon_small").Source = "";
    MSNWidget.root.findName(Weather.current.weatherIcon.sky+"_small").Visibility = "Visible";

    MSNWidget.root.findName("Provided_By_small").Text = Weather.attribution;
    MSNWidget.root.findName("Current_TimeStamp_small").Text = Weather.current.observationtime;
    MSNWidget.root.findName("Current_TimeStampLocation_small").Text = Weather.current.location;
    
     //Start the animations
    var anim_pop = MSNWidget.root.findName("Image_PopUp_small");
    anim_pop.begin();
    
    var anim_slide = MSNWidget.root.findName("Image_Slide_small");
    anim_slide.begin();
    
    MSNWidget.root.findName("Forecast_SunMoon").begin();
    
    Weather.showFlyout();
 }
 
 Weather.showUndocked = function(){
 
     MSNWidget.root.findName("subcat_text").Text = locale.weather.name;
     
    //Show current weather
    MSNWidget.root.findName("Current_Temp").Text = Weather.current.temperature +unescape("%B0")+Weather.degreetype; 
    MSNWidget.root.findName("Current_FeelsLike_Text").Text = locale.weather.feelslike;
    MSNWidget.root.findName("Current_FeelsLike_Temp").Text = Weather.current.feelslike +unescape("%B0")+Weather.degreetype;
    MSNWidget.root.findName("Current_Conditions").Text = Weather.current.skytext;    

    if(Weather.current.weatherIcon.sunMoonImg != "")
        MSNWidget.root.findName("Current_SunMoonIcon").Source = Weather.imagePath + Weather.current.weatherIcon.sunMoonImg;
    else MSNWidget.root.findName("Current_SunMoonIcon").Source = "";
    
    if(Weather.current.weatherIcon.weatherImg != "")
        MSNWidget.root.findName("Current_WeatherIcon").Source = Weather.imagePath + Weather.current.weatherIcon.weatherImg;
    else MSNWidget.root.findName("Current_WeatherIcon").Source = "";
    MSNWidget.root.findName(Weather.current.weatherIcon.sky).Visibility = "Visible";
    
    MSNWidget.root.findName("Provided_By").Text = Weather.attribution;
    MSNWidget.root.findName("Current_TimeStamp").Text = Weather.current.observationtime;
    if(Weather.current.location)
        MSNWidget.root.findName("Current_TimeStampLocation").Text = Weather.current.location;
    else MSNWidget.root.findName("Current_TimeStampLocation").Text = locale.weather.noLocation;
    
    for(var i = 0; i < Weather.forecast.length; i++){
        if(Weather.forecast[i].weatherIcon.sunMoonImg)
		    MSNWidget.root.findName("Day_"+i+"_SunMoonIcon").Source = Weather.imagePath + Weather.forecast[i].weatherIcon.sunMoonImg;
	    else MSNWidget.root.findName("Day_"+i+"_SunMoonIcon").Source = "";
		
	    if(Weather.forecast[i].weatherIcon && Weather.forecast[i].weatherIcon.sunMoonRotation)
		    MSNWidget.root.findName("Day_"+i+"_SunMoonIcon_Rotation").ScaleX = Weather.forecast[i].weatherIcon.sunMoonRotation;
	    else MSNWidget.root.findName("Day_"+i+"_SunMoonIcon_Rotation").ScaleX= 1;
		
	    if(Weather.forecast[i].weatherIcon.weatherImg.length > 0)
		    MSNWidget.root.findName("Day_"+i+"_WeatherIcon").Source = Weather.imagePath + Weather.forecast[i].weatherIcon.weatherImg;
	    else MSNWidget.root.findName("Day_"+i+"_WeatherIcon").Source="";
		
	    if(Weather.forecast[i].skytextday){
		    MSNWidget.root.findName("Day_"+i+"_Conditions").Text = Weather.forecast[i].skytextday;
		    MSNWidget.root.findName("Day_"+i+"_Conditions").TextWrapping="Wrap";
	    } else {
		    MSNWidget.root.findName("Day_"+i+"_Conditions").Text = locale.weather.notAvailable;
		    MSNWidget.root.findName("Day_"+i+"_Conditions").TextWrapping="Wrap"
	    }
		
	    if(Weather.forecast[i].high)
		    MSNWidget.root.findName("Day_"+i+"_Hi").Text = Weather.forecast[i].high +unescape("%B0")+ Weather.degreetype;
	    else MSNWidget.root.findName("Day_"+i+"_Hi").Text = "";
		
	    if(Weather.forecast[i].low)
		    MSNWidget.root.findName("Day_"+i+"_Lo").Text = Weather.forecast[i].low +unescape("%B0")+ Weather.degreetype;
	    else MSNWidget.root.findName("Day_"+i+"_Lo").Text = "";
		
	    if(Weather.forecast[i].day)
		    MSNWidget.root.findName("Day_"+i+"_Day").Text = Weather.forecast[i].day;
	    else MSNWidget.root.findName("Day_"+i+"_Day").Text = "";
   }
    
    //Start the animations
    var anim_pop = MSNWidget.root.findName("Image_PopUp");
    anim_pop.begin();
    
    var anim_slide = MSNWidget.root.findName("Image_Slide");
    anim_slide.begin();
    
    MSNWidget.root.findName("Forecast_SunMoon").begin();
 }
 
Weather.showFlyout = function(){

    if(!MSNWidget.platformConnector.flyoutShow()){
        MSNWidget.platformConnector.flyoutShow(true);
    } else {
        Flyout.showWeather();
    }
}
 
Weather.clearWeather = function(){
    Weather.current = {temperature: "",
        latitude: 0,
        location: '',
        skycode: 0,
        skytext: "n/a",
        observationtime: "",
        timestamp: 0,
        feelslike: "",
        humidity: 0,
        windspeed: 0,
        weatherIcon: {sunMoonImg:"sunMoon_19.png", weatherImg:"",sky:"Sky_Clear2", sunMoonRotation:""}};
        
    Weather.forecast = new Array(5);
    for(var i = 0; i < Weather.forecast.length; i++){
	    Weather.forecast[i] = {};
	    Weather.forecast[i].day = "";
	    Weather.forecast[i].low = 0;
	    Weather.forecast[i].high = 0;
	    Weather.forecast[i].skycodeday = 0;
	    Weather.forecast[i].skytextday = '';
	    Weather.forecast[i].precip = 0;
	    Weather.forecast[i].weatherIcon = {sunMoonImg:"sunMoon_19.png", weatherImg:"",sky:"Sky_Clear2", sunMoonRotation:""};
    }
    
    if(MSNWidget.platformConnector.isDocked() && !Weather.visible)
        Weather.showSmallWeather(true);
}

Weather.openPage = function(){
    window.open("http://wetter.msn.com/?ocid="+ocid);
}

Weather.loading = function(isLoading){
    var root = (MSNWidget.platformConnector.isDocked() 
                && MSNWidget.platformConnector.flyoutShow()) ? flyoutSL : MSNWidget.root;
    var obj = root.findName("WeatherLoading");
    
    if(isLoading){
        obj.Visibility = "Visible";
        var animation = root.findName("WeatherLoadingIn");
        animation.Begin();
    } else {
        var animation = root.findName("WeatherLoadingOut");
        animation.Begin();
    }
}

function loadedOut(sender, eventArgs){
    sender.findName("WeatherLoading").Visibility = "Collapsed";
}
 
Weather.notAvailable = function(){
    MSNWidget.root.findName("Current_SunMoonIcon").Source = Weather.imagePath + "sunMoon_19.png";
    MSNWidget.root.findName("smallSunMoonImg").Source = Weather.imagePath + "sunMoon_19.png";
}
 
Weather.getLocationData = function(XML){
    var locationNodes = XML.getElementsByTagName('weather');
    var result = new Array();
    
    if(locationNodes.length == 0)
        Weather.noLocationFound();
    
    for(var i = 0; i < locationNodes.length; i++){
        var location = {};
        var node = locationNodes.item(i);
        location.code = node.getAttribute("weatherlocationcode");
        location.name = node.getAttribute("weatherlocationname");
        location.latitude = node.getAttribute("lat");
        
        var currentNode = node.getElementsByTagName('current').item(0);
        location.temperature = currentNode.getAttribute("temperature");
        location.skycode = currentNode.getAttribute("skycode");
        location.skytext = currentNode.getAttribute("skytext");
        
        location.weatherImage = Weather.WeatherImage(location.skycode, null, null, null);        
        
        result.push(location);
    }
    
    Weather.makeLocationResult(result);
}

Weather.makeLocationResult = function(result){
    var root = (MSNWidget.platformConnector.isDocked()) ? flyoutSL : MSNWidget.root;

    //Calculate the right sizes
    var width = root.findName("LocationSelectionBg").width - 24;
    var fontSize = (MSNWidget.platformConnector.isDocked()) ? 10 : 12;

    for(var x = 0; x < result.length; x++){
    
        var location = result[x];
    
        var xaml_str = '<Canvas xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="'+(width)+'" Height="20" Canvas.Left="0" Canvas.Top="'+(x*20+x)+'">';
        xaml_str += '<Rectangle x:Name="SearchLocationSelected_'+x+'" Cursor="Hand" Width="'+(width)+'" Height="20" '+
                    'Fill="#7F3D3D3D" RadiusX="2" RadiusY="2">'
        xaml_str += '<Rectangle.Stroke>';
        xaml_str += '<RadialGradientBrush><RadialGradientBrush.RelativeTransform>';
        xaml_str += '</RadialGradientBrush.RelativeTransform>';
        xaml_str += '<GradientStop Color="#FFFFFFFF" Offset="0"/>';
        xaml_str += '<GradientStop Color="#3FFFFFFF" Offset="1"/>';
        xaml_str += '</RadialGradientBrush></Rectangle.Stroke></Rectangle>';
        xaml_str += '<Rectangle x:Name="SearchLocationSelected_'+x+'_Hover" IsHitTestVisible="False" Width="'+(width)+'" Height="18" ';
        xaml_str += 'Canvas.Left="1" Canvas.Top="1" Opacity="0">';
        xaml_str += '<Rectangle.Fill><LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">';
        xaml_str += '<GradientStop Color="#33E85700" Offset="0"/>';
        xaml_str += '<GradientStop Color="#FFE85700" Offset="0.5"/>';
        xaml_str += '<GradientStop Color="#FFC44900" Offset="0.51"/>';
        xaml_str += '<GradientStop Color="#CCA83F00" Offset="1"/>';
        xaml_str += '</LinearGradientBrush></Rectangle.Fill></Rectangle>';
        xaml_str += '<Rectangle IsHitTestVisible="False" Width="100" Height="18" RadiusX="2" RadiusY="2" Canvas.Left="'+(width-100)+'" Canvas.Top="1">';
        xaml_str += '<Rectangle.Fill><LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">';
        xaml_str += '<GradientStop Color="#FF000000" Offset="0"/>';
        xaml_str += '<GradientStop Color="#00000000" Offset="1"/>';
        xaml_str += '</LinearGradientBrush></Rectangle.Fill></Rectangle>';
        xaml_str += '<TextBlock x:Name="LocCode_'+x+'" Visibility="Collapsed" />';
        xaml_str += '<TextBlock x:Name="LocName_'+x+'" IsHitTestVisible="False" Width="400" Height="18" Canvas.Left="3" Canvas.Top="3" FontFamily="Arial" FontSize="'+fontSize+'" Foreground="#B2FFFFFF" TextWrapping="Wrap" FontStyle="Normal"/>';
        xaml_str += '<Image IsHitTestVisible="False" Width="20" Height="20" Canvas.Left="'+(width - 85)+'" x:Name="LocSunMoon_'+x+'" Canvas.Top="0"/>';
        xaml_str += '<Image IsHitTestVisible="False" Width="20" Height="20" Canvas.Left="'+(width - 85)+'" x:Name="LocCond_'+x+'" Canvas.Top="0"/>';
        xaml_str += '<TextBlock IsHitTestVisible="False" x:Name="LocCurrTemp_'+x+'" Width="40" Height="18" Canvas.Left="'+(width - 35 )+'" Canvas.Top="3" FontFamily="Arial" FontSize="12" Foreground="#FFFFFFFF" TextWrapping="Wrap" FontStyle="Normal"/>';
        xaml_str += '<Rectangle IsHitTestVisible="False" Width="1" Height="18" Canvas.Left="'+(width-101)+'" Canvas.Top="1"><Rectangle.Fill>';
        xaml_str += '<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">';
        xaml_str += '<GradientStop Color="#7F000000" Offset="0"/>';
        xaml_str += '<GradientStop Color="#7F000000" Offset="1"/>';
        xaml_str += '<GradientStop Color="#FF000000" Offset="0.5"/>';
        xaml_str += '</LinearGradientBrush></Rectangle.Fill></Rectangle>';
        xaml_str += '<Rectangle IsHitTestVisible="False" Width="1" Height="18" Canvas.Left="'+(width-100)+'" Canvas.Top="1">';
        xaml_str += '<Rectangle.Fill><LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">';
        xaml_str += '<GradientStop Color="#33FFFFFF" Offset="0"/>';
        xaml_str += '<GradientStop Color="#33FFFFFF" Offset="1"/>';
        xaml_str += '<GradientStop Color="#7FFFFFFF" Offset="0.5"/></LinearGradientBrush></Rectangle.Fill></Rectangle>';
        xaml_str += '<Rectangle IsHitTestVisible="False" Width="1" Height="18" Canvas.Left="'+(width-51)+'" Canvas.Top="1">';
        xaml_str += '<Rectangle.Fill><LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">';
        xaml_str += '<GradientStop Color="#7F000000" Offset="0"/>';
        xaml_str += '<GradientStop Color="#7F000000" Offset="1"/>';
        xaml_str += '<GradientStop Color="#FF000000" Offset="0.5"/>';
        xaml_str += '</LinearGradientBrush></Rectangle.Fill></Rectangle>';
        xaml_str += '<Rectangle IsHitTestVisible="False" Width="1" Height="18" Canvas.Left="'+(width-50)+'" Canvas.Top="1">';
        xaml_str += '<Rectangle.Fill><LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">';
        xaml_str += '<GradientStop Color="#33FFFFFF" Offset="0"/>';
        xaml_str += '<GradientStop Color="#33FFFFFF" Offset="1"/>';
        xaml_str += '<GradientStop Color="#7FFFFFFF" Offset="0.5"/>';
        xaml_str += '</LinearGradientBrush></Rectangle.Fill></Rectangle></Canvas>';
        
        var xaml_obj = root.getHost().content.createFromXaml(xaml_str);
        xaml_obj.findName("LocName_"+x).Text = location.name;
        xaml_obj.findName("LocCode_"+x).Text = location.code;
        xaml_obj.findName("LocCurrTemp_"+x).Text = location.temperature;
        if(location.weatherImage.sunMoonImg != "")
            xaml_obj.findName("LocSunMoon_"+x).Source = Weather.imagePath + location.weatherImage.sunMoonImg;
        else xaml_obj.findName("LocSunMoon_"+x).Source = "";
        xaml_obj.findName("LocCond_"+x).Source = Weather.imagePath + location.weatherImage.weatherImg;
        xaml_obj.findName('SearchLocationSelected_'+x).addEventListener("MouseEnter", Weather.loc_mouseIn);
        xaml_obj.findName('SearchLocationSelected_'+x).addEventListener("MouseLeave", Weather.loc_mouseOut);
        xaml_obj.findName('SearchLocationSelected_'+x).addEventListener("MouseLeftButtonDown", Weather.loc_mouseClick);
        root.findName("WeatherContent").children.add(xaml_obj);
    }
    //Reset the content-area
    root.findName("WeatherContent")["Canvas.Top"] = 0;
    
    //Adjust the scrollbar
    if(MSNWidget.platformConnector.isDocked())
        Flyout.scrollbar.sizeSlider();
    else
        Weather.scrollbar.sizeSlider();
}

Weather.noLocationFound  = function(){

}

//Shows a list of all the previosly selected weatherlocations
Weather.showLocationList = function(){
    var root = (MSNWidget.platformConnector.isDocked()) ? flyoutSL : MSNWidget.root;

    if(Weather.locations.length == 0)return;
   
    var width = root.findName("LocationSelectionBg").Width - 20;
    
    for(var x = 1; x < this.locations.length; x++){
        var xaml_str = '<Canvas xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="'+width+'" ';
        xaml_str += 'Height="20" Canvas.Left="0" Canvas.Top="'+((x-1)*20+x)+'">';
        xaml_str += '<Rectangle x:Name="WeatheLocationSelected_'+x+'" ';
        xaml_str += 'MouseLeave="WeatherLocationSearch_RollOut" Cursor="Hand" Width="'+width+'" Height="20" Fill="#7F3D3D3D" ';
        xaml_str += 'RadiusX="2" RadiusY="2">';
        xaml_str += '<Rectangle.Stroke><RadialGradientBrush>';
        xaml_str += '<RadialGradientBrush.RelativeTransform><TransformGroup>';
        xaml_str += '<ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.052" ScaleY="2.306"/>';
        xaml_str += '<SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>';
        xaml_str += '<RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>';
        xaml_str += '<TranslateTransform X="0" Y="-0.072"/></TransformGroup>';
        xaml_str += '</RadialGradientBrush.RelativeTransform>';
        xaml_str += '<GradientStop Color="#FFFFFFFF" Offset="0"/>';
        xaml_str += '<GradientStop Color="#3FFFFFFF" Offset="1"/></RadialGradientBrush></Rectangle.Stroke></Rectangle>';
        
        xaml_str += '<Rectangle x:Name="WeatheLocationSelected_'+x+'_Hover" IsHitTestVisible="False" Width="'+(width-2)+'" ';
        xaml_str += 'Height="18" Canvas.Left="1" Canvas.Top="1" Opacity="0" RadiusX="2" RadiusY="2"><Rectangle.Fill>';
        xaml_str += '<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">';
        xaml_str += '<GradientStop Color="#33E85700" Offset="0"/>';
        xaml_str += '<GradientStop Color="#FFE85700" Offset="0.5"/>';
        xaml_str += '<GradientStop Color="#FFC44900" Offset="0.51"/>';
        xaml_str += '<GradientStop Color="#CCA83F00" Offset="1"/>';
        xaml_str += '</LinearGradientBrush></Rectangle.Fill></Rectangle>';
        
        xaml_str += '<TextBlock x:Name="LocationName_'+x+'" IsHitTestVisible="False" Width="400" Height="18" ';
        xaml_str += 'Canvas.Left="8" Canvas.Top="3" FontFamily="Arial" FontSize="12" Foreground="#B2FFFFFF" ';
        xaml_str += 'TextWrapping="Wrap" FontStyle="Normal"/></Canvas>'
        
        var xaml_obj = root.getHost().content.createFromXaml(xaml_str);
        xaml_obj.findName("LocationName_"+x).Text = this.locations[x];
        xaml_obj.findName('WeatheLocationSelected_'+x).addEventListener("MouseEnter", Weather.loc_mouseIn);
        xaml_obj.findName('WeatheLocationSelected_'+x).addEventListener("MouseLeave", Weather.loc_mouseOut);
        xaml_obj.findName('WeatheLocationSelected_'+x).addEventListener("MouseLeftButtonDown", Weather.loc_mouseClick);
        root.findName("WeatherContent").children.add(xaml_obj);        
    }
}

Weather.loc_mouseIn = function(sender, mouseEventArgs){
    var animation = sender.findName("BtnHoverIn");
    if(animation == null)return;
    var btn = sender.name + "_Hover";
    animation.Stop();
    animation["Storyboard.TargetName"] = btn;
    animation.Begin();
}

Weather.loc_mouseOut = function(sender, mouseEventArgs){
    var animation = sender.findName("BtnHoverOut");
    if(animation == null)return;
    animation.Stop();
    animation["Storyboard.TargetName"] = sender.name + "_Hover";
    animation.Begin();
}

Weather.loc_mouseClick = function(sender, mouseEventArgs){
    var root = (MSNWidget.platformConnector.isDocked()) ? flyoutSL : MSNWidget.root;
    //find out, which index the clicked location has
    var index = sender.Name.substring(23);
    var prefix = sender.Name.substring(0, 6);
    
    if(index != "" && prefix == "Weathe"){
        
        index = parseInt(index);
        //Rearrange the locations, so that the selected location is first
        var location = new Array(Weather.locations[index]);
        var locationCode = new Array(Weather.locationCodes[index]);
        Weather.locations.splice(index, 1);
        Weather.locationCodes.splice(index, 1);
        
        Weather.locations = location.concat(Weather.locations);
        Weather.locationCodes = locationCode.concat(Weather.locationCodes);
    } else if(index != "" && prefix == "Search"){
        var obj_name = sender.findName("LocName_"+index);
        var obj_code = sender.findName("LocCode_"+index);
        var location = new Array(obj_name.Text);
        var locationCode = new Array(obj_code.Text);
        Weather.locations = location.concat(Weather.locations);
        Weather.locationCodes = locationCode.concat(Weather.locationCodes);
    } else return;
    
        Weather.save();
        MSNWidget.weatherSearchBar.clear();
        Weather.click_ChangeLocation(root.findName("Weather_CancelChangeLocation"), null);
        Weather.send(Weather.locationCodes[0]);
    
}

Weather.clearLocationList = function(){
    var root = (MSNWidget.platformConnector.isDocked()) ? flyoutSL : MSNWidget.root;
    root.findName("WeatherContent").children.clear();
}

Weather.clearLocations = function(){
   Weather.locations.splice(1, Weather.locations.length - 1);
   Weather.locationCodes.splice(1, Weather.locationCodes.length - 1);
}

Weather.showLocationScrollbar = function(){
    
}

Weather.GetWeatherData = function(weatherXML, reqDegType){
	//try{
	 if(typeof(weatherXML) == "undefined")return;
	
		var currentWeatherNode = weatherXML.getElementsByTagName('current').item(0),
		    recdDegType = weatherXML.getElementsByTagName('weather').item(0).getAttribute('degreetype'),
		    weatherNode = weatherXML.getElementsByTagName('weather').item(0);
		    

		
		if(currentWeatherNode!=null){
			
			var latitude = weatherNode.getAttribute('lat');
			if(latitude)
				Weather.current.latitude=latitude;
			
			var location = weatherNode.getAttribute('weatherlocationname');
			if(location)
			    Weather.current.location = location;
			    
			var url = weatherNode.getAttribute('url');
			if(url)
			    Weather.msnURL = url;
			
			var temp = currentWeatherNode.getAttribute('temperature');
			if(temp)
				Weather.current.temperature = Weather.ConvertTemp(temp,recdDegType,reqDegType);
			
			var skytext = currentWeatherNode.getAttribute('skytext');
			if(skytext)
				Weather.current.skytext = skytext;
			
			var feelsLike = currentWeatherNode.getAttribute('feelslike');
			if(feelsLike)
			    Weather.current.feelslike = Weather.ConvertTemp(feelsLike,recdDegType,reqDegType);
			
			var time = currentWeatherNode.getAttribute('observationtime');
			var formattedTime = Weather.returnTimeString(time);
			if(formattedTime){
				Weather.current.observationtime = locale.weather.loc_asOf+" "+formattedTime+" "+locale.weather.loc_in;
				var timezone=Number(weatherXML.getElementsByTagName('weather').item(0).getAttribute('timezone'));
				
				if(isNaN(timezone))
				    timezone=0;
				var date=currentWeatherNode.getAttribute('date'),
				    dateParts=date.split("-"),
				    dateTime=dateParts[1]+"-"+dateParts[2]+"-"+dateParts[0]+" "+time,
				    timestamp=Date.parse(dateTime);
				if(!isNaN(timestamp))
					Weather.current.timestamp=timestamp-timezone*3600000;
			}
			
			if(currentWeatherNode.getAttribute('skycode')
			    && currentWeatherNode.getAttribute('observationtime')
			    && (currentWeatherNode.getAttribute('date')
			        && Weather.current.latitude))
				Weather.current.weatherIcon = Weather.WeatherImage(currentWeatherNode.getAttribute('skycode'),
				    currentWeatherNode.getAttribute('observationtime'),
				    currentWeatherNode.getAttribute('date'),Weather.current.latitude);
				
			var attribution = weatherNode.getAttribute('attribution');
			if(attribution)
			    Weather.attribution=attribution;
			    
			Weather.degreeType=reqDegType
		}
		
		var forecastNodeList = weatherXML.getElementsByTagName('forecast');
		if(forecastNodeList != null && forecastNodeList.length > 0){
		
			var datePart = currentWeatherNode.getAttribute('date').split("-"),
				currDate = new Date(Number(datePart[0]),Number(datePart[1])-1,Number(datePart[2])),
				day = currDate.getDay();
			for(var i=0; i<forecastNodeList.length; i++){
				var foreCastNode=forecastNodeList[i];
				
				var high=foreCastNode.getAttribute('high');
				if(high)
					Weather.forecast[i].high = Weather.ConvertTemp(high,recdDegType,reqDegType);
				
				var low=foreCastNode.getAttribute('low');
				if(low)
					Weather.forecast[i].low = Weather.ConvertTemp(low,recdDegType,reqDegType);
					
				var skytextday = foreCastNode.getAttribute('skytextday');
				if(skytextday)
					Weather.forecast[i].skytextday=skytextday;
				
				var skycodeday = foreCastNode.getAttribute('skycodeday');
				if(skycodeday)
					Weather.forecast[i].weatherIcon = Weather.WeatherImage(skycodeday,null,null,null,null);

				Weather.forecast[i].day = (i == 0) ? "Heute" : locale.weather.days[day];
				day=++day%7
			}
		}
		Weather.weatherXML = weatherXML;
}

Weather.WeatherImage = function(skycode,time,date,latitude){
	var lat=Number(latitude),
		nightCode,
		sunMoonRotation=1,
		sunMoonIcon="0",
		weatherIcon="0",
		sky="Sky_Day_Blue";
	
	switch(Number(skycode)){
		case 1:sky="Sky_Day_Grey";weatherIcon="6";break;
		case 2:sky="Sky_Day_Grey";weatherIcon="6";break;
		case 3:sky="Sky_Day_Grey";weatherIcon="6";break;
		case 4:sky="Sky_Day_Grey";weatherIcon="6";break;
		case 5:sky="Sky_Day_Grey";weatherIcon="12";break;
		case 6:sky="Sky_Day_Grey";weatherIcon="29";break;
		case 7:sky="Sky_Day_Grey";weatherIcon="24";break;
		case 8:sky="Sky_Day_Grey";weatherIcon="14";break;
		case 9:sky="Sky_Day_Grey";weatherIcon="5";break;
		case 10:sky="Sky_Day_Grey";weatherIcon="14";break;
		case 11:sky="Sky_Day_Grey";weatherIcon="5";break;
		case 12:sky="Sky_Day_Grey";weatherIcon="5";break;
		case 13:sky="Sky_Day_Grey";weatherIcon="11";break;
		case 14:sky="Sky_Day_Grey";weatherIcon="27";break;
		case 15:sky="Sky_Day_Grey";weatherIcon="17";break;
		case 16:sky="Sky_Day_Grey";weatherIcon="11";break;
		case 17:sky="Sky_Day_Grey";weatherIcon="6";break;
		case 18:sky="Sky_Day_Grey";weatherIcon="25";break;
		case 19:sky="Sky_Day_Dust";sunMoonIcon="17";weatherIcon="15";break;
		case 20:weatherIcon="9";break;
		case 21:weatherIcon="10";break;
		case 22:sky="Sky_Day_Grey";weatherIcon="8";break;
		case 23:weatherIcon="16";break;
		case 24:weatherIcon="16";break;
		case 25:weatherIcon="18";break;
		case 26:sky="Sky_Day_Grey";weatherIcon="4";break;
		case 27:nightCode=true;weatherIcon="19";break;
		case 28:sky="Sky_Day_Grey";nightCode=false;sunMoonIcon="17";weatherIcon="3";break;
		case 29:nightCode=true;weatherIcon="19";break;
		case 30:nightCode=false;sunMoonIcon="17";weatherIcon="3";break;
		case 31:nightCode=true;break;
		case 32:nightCode=false;sunMoonIcon="17";break;
		case 33:nightCode=true;weatherIcon="20";break;
		case 34:nightCode=false;sunMoonIcon="17";weatherIcon="1";break;
		case 35:sky="Sky_Day_Grey";weatherIcon="6";break;
		case 36:nightCode=false;sunMoonIcon="18";break;
		case 37:nightCode=false;sunMoonIcon="17";weatherIcon="7";break;
		case 38:nightCode=false;sunMoonIcon="17";weatherIcon="7";break;
		case 39:nightCode=false;sunMoonIcon="17";weatherIcon="2";break;
		case 40:sky="Sky_Day_Grey";weatherIcon="28";break;
		case 41:nightCode=false;sunMoonIcon="17";weatherIcon="13";break;
		case 42:sky="Sky_Day_Grey";weatherIcon="26";break;
		case 43:sky="Sky_Day_Grey";weatherIcon="26";break;
		case 45:nightCode=true;weatherIcon="21";break;
		case 46:nightCode=true;weatherIcon="23";break;
		case 47:nightCode=true;weatherIcon="22";break;
		default:sky="Sky_Day_Grey";nightCode=false;sunMoonIcon="19";break;
	}
		
	if(time!=null&&nightCode!=false){
		var t=time.split(":"),h=t[0];
		if(h>17)
			nightCode=true
	}
	
	if(nightCode==true)
		sky="Sky_Night";
	
	if(nightCode&&time!=null&&date!=null){
		var lunarcycle=29.5305888531,cD=date.split("-"),
			startDate=new Date(2008,7,1,10,13,0),
			forecastDate=new Date(cD[0],cD[1]-1,cD[2],t[0],t[1],0),
			lunarphase=(Date.parse(forecastDate)-Date.parse(startDate))/1000/60/60/24,
			lunarday=lunarphase/lunarcycle-Math.floor(lunarphase/lunarcycle);
		
		moonage=Math.round(lunarcycle*lunarday);
		switch(moonage){
			case 1:sunMoonIcon="1";break;
			case 2:sunMoonIcon="1";break;
			case 3:sunMoonIcon="2";break;
			case 4:sunMoonIcon="3";break;
			case 5:sunMoonIcon="3";break;
			case 6:sunMoonIcon="4";break;
			case 7:sunMoonIcon="4";break;
			case 8:sunMoonIcon="5";break;
			case 9:sunMoonIcon="6";break;
			case 10:sunMoonIcon="6";break;
			case 11:sunMoonIcon="7";break;
			case 12:sunMoonIcon="7";break;
			case 13:sunMoonIcon="8";break;
			case 14:sunMoonIcon="9";break;
			case 15:sunMoonIcon="9";break;
			case 16:sunMoonIcon="9";break;
			case 17:sunMoonIcon="10";break;
			case 18:sunMoonIcon="11";break;
			case 19:sunMoonIcon="11";break;
			case 20:sunMoonIcon="12";break;
			case 21:sunMoonIcon="12";break;
			case 22:sunMoonIcon="13";break;
			case 23:sunMoonIcon="14";break;
			case 24:sunMoonIcon="14";break;
			case 25:sunMoonIcon="15";break;
			case 26:sunMoonIcon="15";break;
			case 27:sunMoonIcon="16";break;
			case 28:sunMoonIcon="16";break;
			case 29:sunMoonIcon="1";break;
			case 30:sunMoonIcon="1";break;
			default:sunMoonIcon="9";break
		}
		
		if(lat<0)sunMoonRotation=-1
	}else if(nightCode&&time==null&&date==null)
		sunMoonIcon="7";
	
	var w=new Object;
	w.weatherImg="weather_"+weatherIcon+".png";
	w.sunMoonImg="sunMoon_"+sunMoonIcon+".png";
	w.sky=sky;
	w.sunMoonRotation=sunMoonRotation;
	return w
}
	
Weather.ConvertTemp = function(temp,source,dest){
	if(source.toUpperCase()=="C"&&dest.toUpperCase()=="F")
		return Math.round(temp*1.8+32);
	else if(source.toUpperCase()=="F"&&dest.toUpperCase()=="C")
		return Math.round((temp-32)/1.8);
	else return temp
}
	
Weather.returnTimeString = function(time){
    var rT=null;
    if(time&&time.match(/^\d{1,2}:\d{1,2}/)){
        var t=time.split(":"),h=Number(t[0]),m=t[1];
        if(null){
            var ampm;
            if(!h){
                h=12;ampm="am";
            } else if(h==12)
                ampm="pm";
            else if(h>12){
                h-=12;ampm="pm"
            }else ampm="am";
            
            h=h.toString();
            rT=h+":"+m+" "+ampm;
        }else{
            h= h<10 ? "0"+h.toString(): h.toString();
            rT=h+":"+m;
        }
    }return rT;
}

/**************************************************************
*   Weather SearchBar
**************************************************************/

WeatherSearchBar = function(){

    this.obj_cnv = "";
    this.obj_txt = "";
    this.obj_cursor = "";
    this.obj_searchBtn = "";
    this.txt = "";
    this.hasFocus = false;
    this.keyDown = false;
    this.root = null;
}

WeatherSearchBar_init = function() {
    
    WeatherSearchBar.prototype.init = function(root){
        this.root = root;
        this.obj_cnv = root.findName("WeatherSearchBox");
        this.obj_txt = root.findName("WeatherSearchBox");
        this.obj_searchBtn = root.findName("cnvSBNormal1");
        
        var obj_txt_search = root.findName("SearchForYourLocation");
        obj_txt_search.Text = locale.weather.searchForLoc;

        this.obj_searchBtn.addEventListener("MouseLeftButtonDown", delegate(this, this.BtnClick));
        this.obj_cnv.addEventListener("GotFocus", delegate(this, this.TextClick));
        this.obj_cnv.addEventListener("MouseEnter", delegate(this, this.mouseIn));
        this.obj_cnv.addEventListener("MouseLeave", delegate(this, this.mouseOut));
        this.root.findName("SearchForYourLocation").addEventListener("MouseLeftButtonDown", delegate(this, this.TextClick));
        root.addEventListener("KeyDown", delegate(this, this.onKeyDown));
        var obj_btn = root.findName("cnvWeatherLocation");
        obj_btn.addEventListener("MouseEnter", delegate(this, this.btn_enter));
        obj_btn.addEventListener("MouseLeave", delegate(this, this.btn_leave));
        obj_btn.addEventListener("MouseLeftButtonDown", delegate(this, this.btn_down));
    };

    WeatherSearchBar.prototype.btn_down = function(sender, mouseEventArgs){
        var animation = this.root.findName("sb_location_down");
        animation.begin();
        this.BtnClick(sender, mouseEventArgs);
    };

    WeatherSearchBar.prototype.btn_enter = function(sender, mouseEventArgs){
        var animation = this.root.findName("sb_location_in");
        animation.begin();
    };

    WeatherSearchBar.prototype.btn_leave = function(sender, mouseEventArgs){
        var animation = this.root.findName("sb_location_out");
        animation.begin();
    };

    WeatherSearchBar.prototype.TextClick = function(sender, eventArgs){
        
        if(this.hasFocus)return;

        this.obj_txt.Text = "";
        this.root.findName("SearchForYourLocation").Visibility = "Collapsed";
        this.hasFocus = true;
        //this.obj_cnv.Focus();
    };

    WeatherSearchBar.prototype.BtnClick = function(sender, eventArgs){
        //this.obj_cursor.Visibility = "Collapsed";
        var animation = this.root.findName("sb_location_up");
        animation.begin();
        Weather.clearLocationList();
        Weather.search(this.obj_txt.Text);
        this.onLooseFocus(sender, eventArgs);
        
        this.obj_txt.Text = "";
    };

    WeatherSearchBar.prototype.onLooseFocus = function(sender, eventArgs){

        if(!this.hasFocus)return;
        if(eventArgs.Source.Name == "SearchBar_Bg" ||
          eventArgs.Source.Name == "SearchBar_Txt" ||
          (eventArgs.Source.getParent() != null && 
            eventArgs.Source.getParent().getParent() != null &&
            eventArgs.Source.getParent().getParent().Name == "SearchBar_More_Container"))return;
        
        this.hasFocus = false;
        
        this.obj_cnv.Text = ""; 
        this.root.findName("SearchForYourLocation").Visibility = "Visible";
        this.hasFocus = false;
        this.root.findName("SearchBar_hidden").Focus();
    };

    WeatherSearchBar.prototype.clear = function(){
        this.obj_txt.Text = "";
        this.txt = "";
        Weather.clearLocationList();
    };

    WeatherSearchBar.prototype.onKeyDown = function(sender, eventArgs){
    
        //If no focus, abort
        if(!this.hasFocus)return;
        
        switch(eventArgs.Key) {
        
          case 3: {
            this.BtnClick(null, eventArgs);
            break;
          }
        }
    };
    
    WeatherSearchBar.prototype.mouseIn = function(sender, eventArgs){
        document.getElementById("MSNSilverlightHost").onclick = function(){};
    };

    WeatherSearchBar.prototype.mouseOut = function(sender, eventArgs){
        document.getElementById("MSNSilverlightHost").onclick = null;
    };
}

/****************************************************************
* Scrollbar
****************************************************************/
Scrollbar = function(){
    this.obj_arrow_top = null;
    this.obj_arrow_bottom = null;
    this.obj_arrow_slider = null;
    this.obj_area = null;
    this.obj_scrollbar = null;
    this.effectiveHeight = 0;
    this.isScrolling = "false";
    this.scrollInterval = null;
    this.mouseY = 0;
    this.LeftMouseBtnPrsd = false;
    this.root = null;
}

Scrollbar_Init = function(){

    Scrollbar.prototype.init = function(root){
        this.root = root;
    
        this.obj_arrow_top = this.root.findName("ScrollArrowUp");
        this.obj_arrow_bottom = this.root.findName("ScrollArrowDown");
        this.obj_arrow_slider = this.root.findName("ScrollGripper");
        this.obj_area = this.root.findName("WeatherContent");
        this.obj_scrollbar = this.root.findName("ScrollBar");
        
        this.obj_arrow_top.addEventListener("MouseLeftButtonDown", delegate(this, this.click));
        this.obj_arrow_bottom.addEventListener("MouseLeftButtonDown", delegate(this, this.click));
        this.obj_scrollbar.addEventListener("MouseLeftButtonDown", delegate(this, this.click));
        
        //Important for avoiding the drag&drop-feature of the gadget
        this.obj_scrollbar.addEventListener("MouseEnter", delegate(this, this.mouseEnter));
        this.obj_scrollbar.addEventListener("MouseEnter", delegate(this, this.mouseLeave));
        
        this.obj_arrow_top.addEventListener("MouseLeftButtonUp", delegate(this, this.releaseClick));
        this.obj_arrow_bottom.addEventListener("MouseLeftButtonUp", delegate(this, this.releaseClick));
        this.obj_scrollbar.addEventListener("MouseLeftButtonUp", delegate(this, this.releaseClick));
        
        this.obj_scrollbar.addEventListener("MouseMove", delegate(this, this.mouseMove));
    };

    Scrollbar.prototype.reset = function(){
       this.obj_area["Canvas.Top"] = 0;
    };

    Scrollbar.prototype.move = function(sender, mouseEventArgs){

    };

    Scrollbar.prototype.scrollDown = function(amount){
        if(this.obj_area == null || this.obj_area.children.count == 0)return;
        
        var areaHeight = this.obj_area.children.count * this.obj_area.children.getItem(0).Height;
        var scroll_left = areaHeight - this.obj_area.Height + this.obj_area["Canvas.Top"];

        if(scroll_left < -10){
            if(this.scrollInterval != null){
                window.clearInterval(this.scrollInterval);
                this.scrollInterval = null;
            }
            return;
        }else {
            if(amount == null){
                this.obj_area["Canvas.Top"]--;
            }
            else {
                if(scroll_left - amount > -10)
                this.obj_area["Canvas.Top"] -= amount;
            }
            
            this.adjustSlider();
        }
    };

    Scrollbar.prototype.scrollUp = function(amount){
        if(this.obj_area == null || this.obj_area.children.count == 0)return;
        
        if(this.obj_area["Canvas.Top"] > 0){
            if(this.scrollInterval != null){
                window.clearInterval(this.scrollInterval);
                this.scrollInterval = null;
            }
            return;
        }else {
             if(amount == null)
                this.obj_area["Canvas.Top"]++;
            else {
                if(amount + this.obj_area["Canvas.Top"] < 0)
                    this.obj_area["Canvas.Top"] += amount;
            }
            
            this.adjustSlider();
        }
    };


    Scrollbar.prototype.sizeSlider = function(){
        var areaHeight = (this.obj_area.children.count * this.obj_area.children.getItem(0).Height) + this.obj_area.children.count;
        var viewport = this.obj_area.Height;
        if(viewport > areaHeight)
            this.obj_scrollbar.Visibility = "Collapsed";
        else {
            this.obj_scrollbar.Visibility = "Visible";
            this.obj_arrow_slider.Height = (viewport / areaHeight) * (viewport - 30);
        }
        
    }

    Scrollbar.prototype.adjustSlider = function(){
        
        var areaHeight = (this.obj_area.children.count * this.obj_area.children.getItem(0).Height) + this.obj_area.children.count;
        var viewport = this.obj_area.Height;
        
        //The Amount of pixels, which the area can be scrolled
        var scrollHeight = areaHeight - viewport;
        
        var ratio = Math.abs(this.obj_area["Canvas.Top"]) / scrollHeight;
        var offset = this.obj_arrow_top.Height + this.obj_arrow_top["Canvas.Top"];
        
        this.obj_arrow_slider["Canvas.Top"] = (this.obj_scrollbar.Height - this.obj_arrow_slider.Height) * ratio;
    };

    Scrollbar.prototype.click = function(sender, mouseEventArgs){
        sender.CaptureMouse();

        switch(sender.Name){
        
            case this.obj_arrow_bottom.Name:
                this.scrollInterval = window.setInterval(delegate(this, this.scrollDown), 10);
                break;
                
            case this.obj_arrow_top.Name:
                this.scrollInterval = window.setInterval(delegate(this, this.scrollUp), 10);
                break;
                
            case this.obj_scrollbar.Name:
                this.mouseY = mouseEventArgs.GetPosition(this.obj_scrollbar).y;
                this.LeftMouseBtnPrsd = true;
                
                break;
        }
    };

    Scrollbar.prototype.releaseClick = function(sender, mouseEventArgs){
        document.getElementById("MSNSilverlightHost").onclick = null;
        if(this.scrollInterval != null){
            window.clearInterval(this.scrollInterval);
            this.scrollInterval = null;
        }
        this.LeftMouseBtnPrsd = false;
        sender.ReleaseMouseCapture();
        
        document.getElementById("MSNSilverlightHost").onclick = null;
    };

    Scrollbar.prototype.mouseMove = function(sender, mouseEventArgs){
        
        var y = mouseEventArgs.getPosition(this.obj_scrollbar).y;

        if(!this.LeftMouseBtnPrsd)return;
        
        if(y < 0 || y > this.obj_scrollbar.Height)return;
        
        //Calculate the scrolling of the area
        var amount_raw = y - this.mouseY;
        
        /*
            How many pixels correspond to 1 pixel on the scrollbar 
        */
        var areaHeight = (this.obj_area.children.count * this.obj_area.children.getItem(0).Height) + this.obj_area.children.count;
        var viewport = this.obj_area.Height;
        
        //The Amount of pixels, which the area can be scrolled
        var scrollHeight = areaHeight - viewport;
        var scrollBarScroll = this.obj_scrollbar.Height - this.obj_arrow_slider.Height;
        var ratio = scrollHeight / scrollBarScroll;
        //debugger;
        if(amount_raw > 0){
            this.scrollDown(amount_raw * ratio);
        } else {
            this.scrollUp(Math.abs(amount_raw * ratio));
        }
        
        this.mouseY = y;
    };

    //If the mouse enters the scrollbar, disable the standard drag&drop-functionality of the sidebar-gadgets
    Scrollbar.prototype.mouseEnter = function(sender, mouseEventArgs){
        document.getElementById("MSNSilverlightHost").onclick = function(e){};
    };

    //If the mouse leave the scrollbar, enable the standard drag&drop-functionality of the sidebar-gadgets
    Scrollbar.prototype.mouseLeave = function(sender, mouseEventArgs){
    };

}

/** Searchbar.js
*
* Die Funktionalität der Suchleiste
* Das wichtigste ist der Nachbau der Funktionalität einer Textbox,
* welche es in Silverlight 1.0 als einzelnes Control nicht gibt.
*
*/

var SearchBar = {};

//Ob die Suchleiste gerade im Fokus ist
SearchBar.hasFocus = false;

//Die Kategorie unter welcher gesucht werden soll
SearchBar.searchcategory = 0;

//Verweis auf die Cursor-Animation
SearchBar.cursoranim = null;

//Verweis auf die Animation, welche die Suchkategorien einblendet
SearchBar.moreanim_in = null;

//Verweis auf die Animation, welche die Suchkategorien ausblendet
SearchBar.moreanim_out = null;
SearchBar.keydown = null;
SearchBar.textCanvas = null;
SearchBar.textElement = null;
SearchBar.textCursor = null;
SearchBar.searchButton = null;
SearchBar.txt_std = null;
SearchBar.txt = null;
SearchBar.se_logo = null;
SearchBar.root = null;


SearchBar.init = function() {
  
  //Das root-Element
  var root = MSNWidget.root;
  
  SearchBar.root = root.findName("SearchBar");
  
  //Die Animation des Cursors
  SearchBar.cursoranim = root.findName("Cursor_blink");
  
  //Die Animation, welche die Kategorie-Knöpfe erscheinen lässt
  SearchBar.moreanim_in = root.findName("SearchBar_More_In");
  
  //Die Animation, welche die Kategorie-Knöpfe verschwinden lässt
  SearchBar.moreanim_out = root.findName("SearchBar_More_Out");
  
  //Wird gerade eine Taste gedrückt?
  SearchBar.keydown = false;
  
  //Das Canvas-Element, welche den TextBlock umgibt
  SearchBar.textCanvas = root.findName("SearchBar_Txt");
  
  //Das TextBlock-Element
  SearchBar.textElement = root.findName("SearchBar_Txt");
  
  //Das Path-Element, welches den Cursor repräsentiert
  SearchBar.textCursor = root.findName("SearchBar_Cursor");
  
  //Der Button, welcher den Suchvorgang einleitet
  SearchBar.searchButton = root.findName("SearchBar_Btn");
  
  //Der StandartText, welche anstatt einer Leeren Textbox angezeigt werden soll
  SearchBar.txt_std = locale.searchbar.srch_label;
  root.findName("SearchBar_Txt").Text = SearchBar.txt_std;
    
  //Der Suchtext
  SearchBar.txt = SearchBar.txt_std;
  
  //The Logo of the SearchEngine being used
  SearchBar.se_logo = root.findName("SE_logo");
    
  root.findName("BingButton").Source = config.image_str + "bing-search.png";
  SearchBar.se_logo.Source = config.image_str + "bing.png";
    
  //Die einzelnen Eventlistener
  SearchBar.se_logo.addEventListener("MouseLeftButtonDown", SearchBar.TextClick);
  SearchBar.textElement.addEventListener("GotFocus", SearchBar.TextClick);
  SearchBar.searchButton.addEventListener("MouseLeftButtonDown", SearchBar.BtnClick);
  root.addEventListener("KeyDown", SearchBar.ProcessKey);
  root.addEventListener("KeyUp", SearchBar.ProcessKeyUp);
  
  //Activate and deactivate the dragging of the gadget, when the mouse enters / leaves the searcbar
  SearchBar.textElement.addEventListener("MouseEnter", SearchBar.mouseIn);
  SearchBar.textElement.addEventListener("MouseLeave", SearchBar.mouseOut);
  
}

SearchBar.resize = function(){
    
    var rootElement = MSNWidget.root;
    var page = document.getElementById("MSNSilverlight");
    var docked = MSNWidget.platformConnector.isDocked();
    
    rootElement.findName("SearchBar_More_Bg").Height = 30;
    
    if(!MSNWidget.platformConnector.isDocked()){
          rootElement.findName("SearchBar_More_Canvas")["Canvas.Top"] = 188;
          rootElement.findName("SearchBar_More_Bg")["Canvas.Top"] = 0;
          rootElement.findName("SearchBar_More_Canvas")["Canvas.Left"] = rootElement.findName("NewsItemsContainer").Width - rootElement.findName("SearchBar_More_Bg").Width - 10;
          var SearchBar_Txt = rootElement.findName("SearchBar_Txt");
          SearchBar_Txt["Height"] = 24;
          SearchBar_Txt["Width"] = rootElement.findName("SearchBar_Txt")["Height"] * 10;
          SearchBar_Txt.Padding = "0";
          rootElement.findName("SearchBar")["Canvas.Top"] = 190;
          rootElement.findName("SearchBar")["Canvas.Left"] = rootElement.findName("NewsItemsContainer").Width - SearchBar_Txt.Width - 10;
          rootElement.findName("SearchBar_More_Bg").Width = rootElement.findName("SearchBar_Txt")["Width"];     
          rootElement.findName("SearchBar_Txt").FontSize = 12;
          rootElement.findName("SearchBar_Txt").Padding = "5,2,0,0";
          rootElement.findName("SearchBar_Txt")["Canvas.Top"] = -2;
          var se_logo = rootElement.findName("SE_logo");
          se_logo.Height = 16;
          se_logo["Canvas.Top"] = 5;
          se_logo["Canvas.Left"] = 68;
          rootElement.findName("BingButton").Height = 20;
          rootElement.findName("BingButton")["Canvas.Top"] = 0;
          rootElement.findName("SearchBar_Options")["Canvas.Left"] = page.offsetWidth - 190;
          rootElement.findName("SearchBar_Download")["Canvas.Left"] = page.offsetWidth - 215;
          rootElement.findName("SearchBar_Usage")["Canvas.Left"] = page.offsetWidth - 165;
          rootElement.findName("SearchBar_Options")["Canvas.Top"] = -205;
          rootElement.findName("SearchBar_Download")["Canvas.Top"] = -205;
          rootElement.findName("SearchBar_Usage")["Canvas.Top"] = -205;
          rootElement.findName("More")["Canvas.Left"] = page.offsetWidth - rootElement.findName("More").ActualWidth - 15;
      }else{
          rootElement.findName("SearchBar")["Canvas.Top"] = 127;
          rootElement.findName("SearchBar")["Canvas.Left"] = 7;
          rootElement.findName("SearchBar_More_Canvas")["Canvas.Left"] = 7;
          rootElement.findName("SearchBar_More_Canvas")["Canvas.Top"] = 125;
          var SearchBar_Txt = rootElement.findName("SearchBar_Txt");
          SearchBar_Txt["Width"] = page.offsetWidth - 16;
          SearchBar_Txt["Height"] = 16;
          SearchBar_Txt.Padding = "0, 0, 0, 0";
          SearchBar_Txt.FontSize = 9.5;
          SearchBar_Txt["Canvas.Top"] = -2;
          var se_logo = rootElement.findName("SE_logo");
          se_logo.Height = 11;
          se_logo["Canvas.Top"] = 2;
          se_logo["Canvas.Left"] = 50;
          rootElement.findName("BingButton").Height = 12;
          rootElement.findName("BingButton")["Canvas.Top"] = 0;
          rootElement.findName("SearchBar_More_Bg")["Canvas.Top"] = 0;
          rootElement.findName("SearchBar_More_Bg").Width = page.offsetWidth - 16;
      }
    
    rootElement.findName("SearchBar_Btn")["Canvas.Left"] = rootElement.findName("SearchBar_Txt")["Width"] - rootElement.findName("BingButton").Height - 2;
    if(MSNWidget.platformConnector.isDocked())
        rootElement.findName("SearchBar_Btn")["Canvas.Left"] -= 4;
}

SearchBar.TextClick = function(sender, eventArgs) {

    /*Wenn auf die "TextBox" geklickt wird, die "TextBox" in den Fokus setzen
    * und alle Vorbereitungen für die Verarbeitung der Eingabe treffen
    */
        //Falls die Suchleiste schon im Fokus ist abbrechen
        if(SearchBar.hasFocus)return;
        else SearchBar.hasFocus = true;
        
         //Falls noch der StandartText in der Suchleiste ist, diesen leeren  
        if(SearchBar.txt.replace(/\s/, "") == SearchBar.txt_std.replace(/\s/, "")){
            SearchBar.txt = "";
            SearchBar.se_logo.Visibility = "Collapsed";    
        }

        //Aktuellen Text im Objekt speichern
        SearchBar.textElement.Text = SearchBar.txt;
        
        //Cursor positionieren und sichtbar machen
        //SearchBar.textCursor["Canvas.Left"] = SearchBar.textElement.ActualWidth + 3;
        //SearchBar.textCursor.opacity = 1;
        
        //die Animationen starten
        //SearchBar.cursoranim.begin();
        SearchBar.moreanim_out.stop();
        SearchBar.moreanim_in.stop();
        SearchBar.moreanim_in.Children.GetItem(0).KeyFrames.GetItem(1).value = -30;
        SearchBar.moreanim_in.begin();
}
  
  /** Die Suchleiste vorbereiten für die Sidebar-Ansicht
  */
SearchBar.showDocked = function(){
  
    var root = MSNWidget.root;
  
    //Den News-Cycle unterbrechen, falls er gerade läuft
    if(GUI.Content.Events.Interval != null)
        window.clearTimeout(GUI.Content.Events.Interval);
        
    //News löschen
    News.clearNews(MSNWidget.root);
    
    //Die GUI vorbereiten
    GUI.update();
    
    //Die Subkategorie-wechsel-Buttons ausblenden und mit der Suchüberschrift ersetzen
    root.findName("subcat_right_btn").Visibility = "Collapsed";
    root.findName("subcat_left_btn").Visibility = "Collapsed";
    root.findName("SubCats").children.clear();
    var xaml_str = '<TextBlock Text="'+locale.searchbar.search_hdr+'" Foreground="#fff" Name="such_txt" FontSize="14" />';
    var xaml_obj = root.getHost().content.createFromXaml(xaml_str);
    root.findName("SubCats").children.add(xaml_obj);
    root.findName("SubCats")["Canvas.Left"] = 0;
    root.findName("such_txt")["Canvas.Left"] = (root.Width / 2) - (root.findName("such_txt").ActualWidth / 2);
}

//Shows or hides the additional Buttons
SearchBar.showButtons = function(show){
    var visibility = (show) ? "Visible" : "Collapsed";
    var root = MSNWidget.root;
    
    root.findName("SearchBar_Options").Visibility = visibility;
    root.findName("SearchBar_Usage").Visibility = visibility;
    root.findName("SearchBar_Download").Visibility = visibility;
}
  
  /* Wenn der Suchvorgang ausgelöst werden soll, entweder durch einen Klick auf den Button
  *  oder Druck auf die Eingabetaste
  */
SearchBar.BtnClick = function(sender, eventArgs) {
  
    //Falls der Text leer ist, oder der StandartText, keinen Suchvorgang auslösen
    if(SearchBar.textElement.Text == "" || SearchBar.textElement.Text == SearchBar.txt_std)return;
  
    //Die richtige Such-URL zu der Kategorie heraussuchen
    var search_str = "";
    if(MSNWidget.platformConnector.isDocked())
        search_str = locale.searchcategories_docked[SearchBar.searchcategory][1];
    else
        search_str = locale.searchcategories[SearchBar.searchcategory][1];
    
    //Den Suchstring escapen und anhängen sowie Tracking-ID anfügen
    search_str += encodeURIComponent(SearchBar.textElement.Text);
    search_str += "&ocid="+ ocid;
    
    eventArgs.Source = MSNWidget.root.findName("NewsItems");
    SearchBar.looseFocus(null, eventArgs);
    SearchBar.txt = SearchBar.txt_std;
    SearchBar.se_logo.visibility = "Visible";
    SearchBar.textElement.Text = SearchBar.txt;
    SearchBar.textCursor["Canvas.Left"] = SearchBar.textElement.ActualWidth + 6;
    window.open(search_str);
    
}
  
/**
* Bei einem Klick außerhalb der Suchleiste, den Fokus von der Leiste entfernen
*/
SearchBar.looseFocus = function(sender, eventArgs) {
    if(!SearchBar.hasFocus)return;
    if(eventArgs == null){}
    else if(eventArgs.Source.Name == SearchBar.textCanvas.Name ||
      eventArgs.Source.Name == SearchBar.textElement.Name ||
      eventArgs.Source.Name == SearchBar.se_logo.Name ||
      (eventArgs.Source.getParent() != null && 
        eventArgs.Source.getParent().getParent() != null &&
        eventArgs.Source.getParent().getParent().Name == "SearchBar_More_Container"))return;

    SearchBar.hasFocus = false;
    MSNWidget.root.findName("SearchBar_hidden").Focus();
   
    //Set the ending-animation to the current state of the "more"-Canvas
    //in case there's currently the "in"-anmition running
    SearchBar.moreanim_out.Children.GetItem(0).KeyFrames.GetItem(0).value = MSNWidget.root.findName("SearchBar_More")["Canvas.Top"];
    SearchBar.cursoranim.stop();
    SearchBar.moreanim_in.stop();
    SearchBar.moreanim_out.stop();
    SearchBar.moreanim_out.begin();
    
    SearchBar.textCursor.opacity = 0;
    
    if(SearchBar.txt.replace(/\s/g, "").length == 0) {
      SearchBar.se_logo.Visibility = "Visible";
      SearchBar.txt = SearchBar.txt_std;
      SearchBar.textElement.Text = SearchBar.txt;
      SearchBar.textCursor["Canvas.Left"] = 0;
    }
    
  }
  
  /**
  * Eingaben bearbeiten
  */
 SearchBar.ProcessKey = function(sender, eventArgs) {
    
    //Falls die Suchleiste keinen Fokus hat, abbrechen
    if(!SearchBar.hasFocus)return;
    
    switch(eventArgs.Key) {
    
    //"Enter" pressed
      case 3: {
        SearchBar.cursoranim.stop();
        SearchBar.textCursor.opacity = 0;
        SearchBar.BtnClick(null, eventArgs);
        break;
      }
      
      //"Escape" pressed
      case 8: {
        SearchBar.txt = "";
        SearchBar.looseFocus(MSNWidget.root, null);
        break;
      }
    }
}
  
  /** Wenn die Taste losgelassen wird
  */
SearchBar.ProcessKeyUp = function(sender, eventArgs) {
    if(eventArgs.Key == 1) {
      SearchBar.keydown = false;
    }
  }
  
//Creates the buttons for the selection of the searchcategory
SearchBar.buildButtons = function(){
    
    var root = MSNWidget.root;
    var btn_width = (MSNWidget.platformConnector.isDocked()) ? config.searchbar.itemWidth_docked : config.searchbar.itemWidth;
    var space = (MSNWidget.platformConnector.isDocked()) ? config.searchbar.itemSpace_docked : config.searchbar.itemSpace;
    var categories = (MSNWidget.platformConnector.isDocked()) ? locale.searchcategories_docked : locale.searchcategories;
    for (var j = 0; j < categories.length; j++) {

          btn_str = '<Canvas Width="' + btn_width + '" Height="30" Name="Btn_' + categories[j][0];
          btn_str += (MSNWidget.platformConnector.isDocked()) ? '" Canvas.Left="' + j%3 * (btn_width + space) + '" Canvas.Top="'+ (Math.floor(j/3)*30) +'"' : '" Canvas.Left="' + j * (btn_width + space) + '"' ;
          btn_str += ' Cursor="Hand">';
          btn_str += '<Rectangle Name="Btn_' + categories[j][0] + '_Hover" Width="' + btn_width + '" Height="30" Opacity="0" RadiusX="5" RadiusY="5">';
          btn_str += '<Rectangle.Fill>';
          btn_str += '<RadialGradientBrush>';
          btn_str += '<GradientStop Color="#99FFFFFF" Offset="0"/>';
          btn_str += '<GradientStop Color="#22FFFFFF" Offset="1"/>';
          btn_str += '</RadialGradientBrush>';
          btn_str += '</Rectangle.Fill>'
          btn_str += '</Rectangle>';
          btn_str += '<Rectangle Name="Btn_' + categories[j][0] + '_Prsd" Width="' + btn_width + '" Height="30" Opacity="0" ';
          
          btn_str += 'RadiusX="5" RadiusY="5">';
          btn_str += '<Rectangle.Fill>';
          btn_str += '<RadialGradientBrush>';
          btn_str += '<GradientStop Color="#FF6AD732" Offset="0"/>';
          btn_str += '<GradientStop Color="#4B6AD732" Offset="1"/>';
          btn_str += '</RadialGradientBrush>';
          btn_str += '</Rectangle.Fill>'
          btn_str += '</Rectangle>';

          btn_str += '<Image Canvas.Top="2" Name="' + categories[j][0] + '_img" Source="" Height="20" />';
          btn_str += '<TextBlock Name="' + categories[j][0] + '_txt" Text="' + categories[j][0] + '" FontSize="9" Canvas.Top="15" Foreground="#FFFFFFFF" />';
          if ((!MSNWidget.platformConnector.isDocked() && j != 0) || (MSNWidget.platformConnector.isDocked() && (j%3 != 0) )) btn_str += '<Path Stroke="#AAFFFFFF" StrokeThickness="2" Data="M0,2V27" />';
          btn_str += '</Canvas>';

          btn_XAML = root.getHost().content.createFromXAML(btn_str);
          btn_XAML.findName(categories[j][0] + "_img").Source = config.image_str + 'searchicon_' + categories[j][0] + '.png';
          root.findName("SearchBar_More_Container").children.add(btn_XAML);
          GUI.Bar.addEvents(btn_XAML);

          //Text und Bild Zentrieren
          btn_XAML.findName(categories[j][0] + "_img")["Canvas.Left"] = (btn_XAML.Width - btn_XAML.findName(categories[j][0] + "_img").ActualWidth) / 2 - 13;
          btn_XAML.findName(categories[j][0] + "_txt")["Canvas.Left"] = (btn_XAML.Width - btn_XAML.findName(categories[j][0] + "_txt").ActualWidth) / 2;
      }
}

SearchBar.mouseIn = function(sender, eventArgs){
    document.getElementById("MSNSilverlightHost").onclick = function(){};
}

SearchBar.mouseOut = function(sender, eventArgs){
    document.getElementById("MSNSilverlightHost").onclick = null;
}

function SearchBar_collapse(sender, eventArgs){
    MSNWidget.root.findName("SearchBar").Visibility = "Collapsed";
    MSNWidget.root.findName("WeatherDisplay").Visibility = "Collapsed";
}

function SearchBar_visible(sender, eventArgs){
    MSNWidget.root.findName("SearchBar").Visibility = "Visible";
}

/** GUI.js
* 
* Enthält alle Funktionen, welche sich mit der GUI befassen, sowie dem Eventhandling
*
*/

var GUI = {};
GUI.Bar = {};
GUI.Bar.Events = {};
GUI.Content = {};
GUI.Content.Events = {};

/* Wird aufgerufen, wenn das Gadget angedockt wird und ändert das Format entsprechend
*/
GUI.docked = function() {

var timeTransition = 0.3;
MSNWidget.platformConnector.beginTransition();

    //Die Handler für die Subkategorie-Buttons umändern und dafür sorgen, dass immer nur 1 Handler aktiv ist
    if (MSNWidget.token_me_r != null) {
        MSNWidget.root.findName("subcat_right_btn").removeEventListener("MouseEnter", MSNWidget.token_me_r);
        MSNWidget.token_me_r = null;
    }
    if (MSNWidget.token_me_l != null) {
        MSNWidget.root.findName("subcat_left_btn").removeEventListener("MouseEnter", MSNWidget.token_me_l);
        MSNWidget.token_me_l = null;
    }

    if (MSNWidget.token_ml_r != null) {
        MSNWidget.root.findName("subcat_right_btn").removeEventListener("MouseLeave", MSNWidget.token_ml_r);
        MSNWidget.token_ml_r = null;
    }
    if (MSNWidget.token_ml_l != null) {
        MSNWidget.root.findName("subcat_left_btn").removeEventListener("MouseLeave", MSNWidget.token_ml_l);
        MSNWidget.token_ml_l = null;
    }
    
    if(MSNWidget.token_md_r == null) {
        MSNWidget.token_md_r = MSNWidget.root.findName("subcat_right_btn").addEventListener("MouseLeftButtonDown", GUI.Bar.switchSubCatsDocked);
    }
    if(MSNWidget.token_md_l == null) {
        MSNWidget.token_md_l = MSNWidget.root.findName("subcat_left_btn").addEventListener("MouseLeftButtonDown", GUI.Bar.switchSubCatsDocked);
    }


    with (document.body.style) {
        width = 135;
        height = 200;
    }
    document.getElementById("MSNSilverlight").style.width = "135px";
    document.getElementById("MSNSilverlight").style.height = "200px";
    
    //Change the background-image for Windows-Versions
    MSNWidget.platformConnector.setBackgroundPNG("../images/gadget-bg-docked.png");
    
    MSNWidget.platformConnector.endTransition(timeTransition);
    
    News.clearNews();
    GUI.update();
    GUI.buildSubcats(MSNWidget.root, MSNWidget.newsCat);
    
    Weather.showSmallWeather(true);
    if(Weather.visible){
        Weather.showWeather();
    } else{
        News.getNews(MSNWidget.newsCat);
    }
}

/**
* Transforms the Gadget from the docked-view to the undocked-view
*/
GUI.undocked = function() {

//Check if the flyout is still visible and if so, close it
if(MSNWidget.platformConnector.flyoutShow())
    MSNWidget.platformConnector.flyoutShow(false);

var timeTransition = 0.3;
MSNWidget.platformConnector.beginTransition();
    //Die Handler für die Subkategorie-Buttons umändern
    if (MSNWidget.token_md_r != null) {
        MSNWidget.root.findName("subcat_right_btn").removeEventListener("MouseLeftButtonDown", MSNWidget.token_md_r);
        MSNWidget.token_md_r = null;
    }
    if (MSNWidget.token_md_l != null) {
        MSNWidget.root.findName("subcat_left_btn").removeEventListener("MouseLeftButtonDown", MSNWidget.token_md_l);
        MSNWidget.token_md_l = null;
    }

    if(MSNWidget.token_me_r == null)
        MSNWidget.token_me_r = MSNWidget.root.findName("subcat_right_btn").addEventListener("MouseEnter", GUI.Bar.switchSubCats);
    if(MSNWidget.token_me_l == null)
        MSNWidget.token_me_l = MSNWidget.root.findName("subcat_left_btn").addEventListener("MouseEnter", GUI.Bar.switchSubCats);

    if(MSNWidget.token_ml_r == null)
        MSNWidget.token_ml_r = MSNWidget.root.findName("subcat_right_btn").addEventListener("MouseLeave", GUI.Bar.stopSubCats);
    if(MSNWidget.token_ml_l == null)
        MSNWidget.token_ml_l = MSNWidget.root.findName("subcat_left_btn").addEventListener("MouseLeave", GUI.Bar.stopSubCats);

    //Set the dimensions. Either fixed values for sidebar-gadget. or 100% width on web
    MSNWidget.platformConnector.setDimensionsLarge();
    
    //Change the background-image
    MSNWidget.platformConnector.setBackgroundPNG("../images/gadget-bg.png");
    
    MSNWidget.platformConnector.endTransition(timeTransition);
    
    News.clearNews();
    GUI.update();
    GUI.buildSubcats(MSNWidget.root, MSNWidget.newsCat);
    
    Weather.showSmallWeather(true);
    if(Weather.visible){
        Weather.showWeather();
    } else{
        News.getNews(MSNWidget.newsCat);
    }
}

GUI.handleLostFocus = function(sender, eventArgs){
    
    if(MSNWidget.platformConnector.isDocked() && MSNWidget.platformConnector.flyoutShow())
        MSNWidget.platformConnector.flyoutShow(false);
}

GUI.looseFocus = function(sender, eventArgs){
    SearchBar.looseFocus(sender, eventArgs);
    if(MSNWidget.root.findName("More").Visibility == "Visible"){
        if(dragdrop.activated){
            return;
        } else if(sender.Name == "root"){
            GUI.Bar.showMore(false);
        } 
    }
}

GUI.Bar.showMore = function(show){

    if(show){
        if(MSNWidget.root.findName("More").Visibility == "Visible")
            return;
            
        MSNWidget.root.findName("More").Opacity = 0;
        MSNWidget.root.findName("More").Visibility = "Visible";
        MSNWidget.root.findName("More_In").begin();
    } else {
        MSNWidget.root.findName("BtnPrsd").stop();
        if(MSNWidget.root.findName("More").Visibility == "Collapsed")
            return;
        
        MSNWidget.root.findName("Btn_More_Prsd").Opacity = 0;
        MSNWidget.root.findName("More").Opacity = 1;
        MSNWidget.root.findName("More_Out").begin();
    }
}

//Is called, when the MoreOut-animation is completed
collapseMore = function(sender, eventArgs){
    MSNWidget.root.findName("More").Visibility = "Collapsed";
}

/**
*   Adds the default-events (Mouse-In, Mouse-Out, Mouse-Click, Mouse-Release) to a given object. 
*/
GUI.Bar.addEvents = function(obj) {
    obj.addEventListener("MouseEnter", GUI.Bar.Events.handleMouseIn);
    obj.addEventListener("MouseLeave", GUI.Bar.Events.handleMouseOut);
    obj.addEventListener("MouseLeftButtonDown", GUI.Bar.Events.handleMouseDown);
    obj.addEventListener("MouseLeftButtonUp", GUI.Bar.Events.handleMouseUp);
  }
 
/**
*   Surveys the mouse movents. Needed for the drag&drop-functionality.
*/ 
GUI.Bar.Events.handleMouseMoveRoot = function(sender, mouseEventArgs) {
    
    //If drag&drop is active (i.e. if a mousebutton is pressed over a button)
    if(dragdrop.activated){
    
        //Obtain the mouseposition relative to the top-left corner of the gadget.
        var pos = mouseEventArgs.getPosition(null);
        
        //If dragging is active or the mouse has moved more than 4 Pixels in any direction
        if(dragdrop.isdragging
            || Math.abs(pos.x - dragdrop.originX) > 4
            || Math.abs(pos.y - dragdrop.orginY) > 4) {
        
            dragdrop.isdragging = true;
            dragdrop.moveBtn(sender, mouseEventArgs);
        } else dragdrop.isdragging = false;
    }

}

//Wenn die Maus im gedockten Zustand über der Kontrollleiste bewegt wird
GUI.Bar.Events.handleMouseMoveBar = function(sender, MouseEventArgs){    
    document.getElementById("MSNSilverlightHost").onclick = function(e){ }
}

//If the mouse leaves the bar-area
GUI.Bar.Events.handleMouseLeaveBar = function(sender, MouseEventArgs){
    document.getElementById("MSNSilverlightHost").onclick = null;
}
  
//Maus ber einem Button
GUI.Bar.Events.handleMouseIn = function(sender, eventArgs) {
    var animation = sender.findName("BtnHoverIn");
    
    if(animation == null)return;
    
    var btn = sender.name + "_Hover";
    animation.Stop();
    animation["Storyboard.TargetName"] = btn;
    animation.Begin();
     
    if (!MSNWidget.platformConnector.isDocked()) {
        if(sender.Name == "Btn_More" && dragdrop.activated)
            GUI.Bar.showMore(true);
    }
  }

//Maus verlsst einen Button
GUI.Bar.Events.handleMouseOut = function(sender, eventArgs) {
    var animation = sender.findName("BtnHoverOut");
    animation.Stop();
    animation["Storyboard.TargetName"] = sender.name + "_Hover";
    animation.Begin();
  }

//Linke Maustaste ber einem Button gedrckt
GUI.Bar.Events.handleMouseDown = function(sender, mouseEventArgs) {
    var animation = sender.findName("BtnPrsd");
    animation.Stop();
    var btn = sender.name + "_Prsd";
    animation["Storyboard.TargetName"] = btn;
    animation.Begin();
    
    //Check the search-buttons
    for(x in locale.searchcategories){
        if(sender.name == "Btn_"+locale.searchcategories[x][0]){
            SearchBar.searchcategory = x;
            SearchBar.BtnClick(null, mouseEventArgs); 
            return;
        }else continue;
    }
   
    if(MSNWidget.platformConnector.isDocked())return;
    //Bei den Kategorie-Buttons die DragDrop-Funktionalität starten
    for(var i = 0; i < MSNWidget.categories.length; i++) {
        if(MSNWidget.categories[i][0] == sender.Name.substr(4)){
            sender.captureMouse();
            dragdrop.activated = true;
            dragdrop.dragObj = sender;
            dragdrop.originX = mouseEventArgs.getPosition(null).x;
            dragdrop.originY = mouseEventArgs.getPosition(null).y;
            dragdrop.start(sender, mouseEventArgs);
            break;
        }
    }
  }
  
//Die Linke Maustaste wird losgelassen und die Funktionalität wird ausgelöst
GUI.Bar.Events.handleMouseUp = function(sender, eventArgs) {
    if(dragdrop.isdragging){
        dragdrop.buttonUp(sender, eventArgs);
     }
     
    dragdrop.activated = false;
    dragdrop.isdragging = false;
    sender.releaseMouseCapture();
    
     if(sender.name != "Btn_More") {
      GUI.Bar.showMore(false);
    }
  
    // Die richtige Kategorie zu dem gedrückten Button herausfinden, oder bei den "Spezial"-Buttons
    // die entsprechende Aktion starten
    var category = 0;
    
    //Cycle through the given news-categories and try to find the right one
    for(x in locale.categories){
        if(sender.name == "Btn_"+locale.categories[x][0]){
            category = locale.categories[x][2];
            break;
        }else continue;
    }    
    
    //Check the special-buttons
    if(category == 0){
        if(sender.name == "Btn_MSN"){window.open("http://www.msn.de?ocid="+ocid);return;}
        else if(sender.name == "smallWeather"){Weather.show(true);return;}
        else if(sender.name == "subcat_text"){
            if(Weather.visible)
                Weather.openPage();
            else News.openCategory();
            return;}
        else if(sender.name == "MSN-Startseite"){window.open("http://www.msn.de?ocid="+ocid);return;}
        else if(sender.name == "Btn_More"){
          if(sender.findName("More").Visibility == "Collapsed") {GUI.Bar.showMore(true);}
          else {
            GUI.Bar.showMore(false);
        } return;}
    }
    
    //If the Weather is visible, hide it
    if(Weather.visible)
        Weather.show(false);

    //Kategorie setzen und News abrufen
    if(category == 0)return;
    MSNWidget.newsCat = category;
    GUI.buildSubcats(sender, Math.floor(category / 100) * 100);
    News.getNews(category);
  }
  
  
/*********************************************
* CONTENT-EVENTS
*
* Every event-related functions, which affect the content of the gadget.
******************************************/
GUI.Content.Events.locked = false;
GUI.Content.Events.Interval = null;

//Unlock user interaction upon the finish of various storyboards
function unlock(sender, eventArgs) {
    GUI.Content.Events.locked = false;
  }
  
//Is called by Storyboard "News2Weather"
function NewsCollapse(sender, eventArgs) {
    MSNWidget.root.findName("NewsItemsContainer").Visibility = "Collapsed";
    MSNWidget.root.findName("Subcat_Scroll").Visibility = "Collapsed";
    MSNWidget.root.findName("SubCats").Visibility = "Collapsed";
}
  
//Maus ueber einem Feed-Eintrag
GUI.Content.Events.handleMouseIn_News = function(sender, eventArgs) {
    if(GUI.Content.Events.locked || typeof(sender) == "undefined")return;
    
    //Clear the timeout, as long as the mouse is over an item
    if(GUI.Content.Events.Interval != null){
        window.clearTimeout(GUI.Content.Events.Interval);
        GUI.Content.Events.Interval = null;
    }
    
    var counter = parseInt(sender.Name.substr(4));
    
    //Start the Mouse-Over-effect, if it's really triggered by a mouse move and not via cycleNews()
    //or if the preview is currently not shown
    if(eventArgs != null && sender.findName("Preview"+counter).Visibility != "Visible"){
        var anim = MSNWidget.root.findName("BtnHoverIn");
        anim.stop();
        anim["StoryBoard.TargetName"] = 'News_canvas'+counter+'_Hover' ;
        anim.begin();
    }
    
    //Change the color of the previously selected Headline if we're in mouseover-mode or if its from cycleNews()
    if(config.news.mouseover || !MSNWidget.platformConnector.isDocked() || eventArgs == null )
        MSNWidget.root.findName("Text"+MSNWidget.news).Foreground = config.news.hl_color;
    
    //Change the color of the selected Headline
    if(config.news.mouseover || !MSNWidget.platformConnector.isDocked() || eventArgs == null )
        MSNWidget.root.findName("Text"+counter).Foreground = config.news.hl_color_focus;
    
    //nur bearbeiten, falls es sich nicht um den aktuellen Beitrag handelt
    if(MSNWidget.news == counter)return;
        
    if (!MSNWidget.platformConnector.isDocked()) {
        
        if(MSNWidget.news != -1){
        
            //If there was an error loading the image, replace it with a default image
            //then start the function again after a short delay
            if(sender.findName("news_img_"+MSNWidget.news)["Height"] == 0){
                window.setTimeout(function(){GUI.Content.Events.handleMouseIn_News(sender, eventArgs);}, 50);
                return;
            }
            
            if(sender.findName("canvas_news_img_"+MSNWidget.news)["Canvas.ZIndex"] > sender.findName("canvas_news_img_"+counter)["Canvas.ZIndex"])
                sender.findName("canvas_news_img_"+counter)["Canvas.ZIndex"] = sender.findName("canvas_news_img_"+MSNWidget.news)["Canvas.ZIndex"] + 1;
            
            var news_img = sender.findName("news_img_"+MSNWidget.news);
            sender.findName("news_img_refl_"+MSNWidget.news)["Canvas.Top"] = sender.findName("news_img_refl_"+MSNWidget.news).Height + news_img.Height + news_img["Canvas.Top"];
           
            //Die "Out"-Animation auf die aktuelle Position des Bildes setzen und abspielen.
            var animOut = sender.findName("NewsImgOut"+MSNWidget.news);
            animOut.stop();
            animOut.Children.GetItem(0).KeyFrames.GetItem(0).value = sender.findName("canvas_news_img_"+MSNWidget.news)["Canvas.Left"];
            animOut.begin();
            
            animOut = sender.findName("NewsImgOut_Scale"+MSNWidget.news);
            animOut.stop();
            animOut.Children.GetItem(0).KeyFrames.GetItem(0).value = sender.findName("news_img_"+MSNWidget.news).Width;
            animOut.Children.GetItem(1).KeyFrames.GetItem(0).value = sender.findName("news_img_"+MSNWidget.news)["Canvas.Top"];
            animOut.Children.GetItem(2).KeyFrames.GetItem(0).value = sender.findName("news_img_"+MSNWidget.news).Width;
            animOut.Children.GetItem(3).KeyFrames.GetItem(0).value = sender.findName("news_img_refl_"+MSNWidget.news)["Canvas.Top"];
            animOut.begin();
        }
        
        MSNWidget.news = counter;
        var ratio = sender.findName("news_img_"+MSNWidget.news).Height / sender.findName("news_img_"+MSNWidget.news).Width;
        if(sender.findName("news_img_"+MSNWidget.news).Height == 0 || isNaN(ratio)){
            window.setTimeout(function(sender, eventArgs){GUI.Content.Events.handleMouseIn_News(sender, eventArgs);}, 50);
            return;
        }
        
        var animIn = sender.findName("NewsImgIn"+counter);
        animIn.begin();
        animInScale = sender.findName("NewsImgIn_Scale"+counter);
        animInScale.stop();
        animInScale.Children.GetItem(3).KeyFrames.GetItem(0).value = 25 + (150*ratio) + (150*ratio);
        animInScale.Children.GetItem(3).KeyFrames.GetItem(1).value = (100*ratio) + (100*ratio);
        animInScale.begin();
        
    } else {
        if(config.news.mouseover || eventArgs == null)
            MSNWidget.news = counter;
        if(config.news.mouseover && eventArgs != null){
            Flyout.addContentToFlyout();
            
            if(!MSNWidget.platformConnector.flyoutShow()){
                MSNWidget.platformConnector.flyoutShow(true);
            }
        }
    }
  }
  
//Maus verlaesst einen Feed-Eintrag
GUI.Content.Events.handleMouseOut_News = function(sender, eventArgs) {
    if(GUI.Content.Events.locked)return;
    
    var counter = parseInt(sender.Name.substr(4));
    
    //Start the hover-animation, if it's really triggered by a mouseEvent
    if(eventArgs != null 
        && sender.findName("Preview"+counter) != null
        && sender.findName("Preview"+counter).Visibility != "Visible"){
        var anim = MSNWidget.root.findName("BtnHoverOut");
        anim.stop();
        anim["StoryBoard.TargetName"] = 'News_canvas'+counter+'_Hover';
        anim.begin();
    }
    
    if(GUI.Content.Events.Interval == null && sender.findName("Preview"+counter).Visibility == "Collapsed")
        GUI.Content.Events.Interval = window.setTimeout("GUI.Content.Events.cycleNews()", config.news.cycletime);
        
    if(MSNWidget.platformConnector.isDocked()){
        var counter = parseInt(sender.Name.substr(4));
        if(counter != MSNWidget.news)
            sender.findName("Text"+counter).Foreground = config.news.hl_color;
    }
  }
  
// Maus klickt auf einen Feed-Eintrag. Artikel öffnen, falls auf das Bild geklickt wurde, die Vorschau anzeigen
// oder im angedockten Zustand
// das Flyout öffnen, falls es noch nicht offen ist.
GUI.Content.Events.handleMouseFeedDown = function(sender, eventArgs) {
    if(GUI.Content.Events.locked)return;
    
    if(MSNWidget.platformConnector.isDocked()) {
    
        //Change the color of the previously selected Headline if we're in mouseover-mode
        if(!config.news.mouseover && MSNWidget.platformConnector.isDocked() )
            MSNWidget.root.findName("Text"+MSNWidget.news).Foreground = config.news.hl_color;
        
        //Change the color of the selected Headline
        if(!config.news.mouseover && MSNWidget.platformConnector.isDocked() )
            MSNWidget.root.findName("Text"+sender.Name.substr(4)).Foreground = config.news.hl_color_focus;
    
        MSNWidget.news = parseInt(sender.Name.substr(4));
        
        GUI.Content.Events.handleMouseIn_News(sender, eventArgs);
        
        if(!MSNWidget.platformConnector.flyoutShow() || !config.news.mouseover){
            MSNWidget.platformConnector.flyoutShow(true);
            Flyout.addContentToFlyout();
        }
        return;
    }
    
    
    if(sender.Name.substring(0,8) != "news_img" && !MSNWidget.platformConnector.isDocked()) {
        if(sender.findName("Preview"+sender.Name.substr(4)).Visibility == "Collapsed"){
            if(GUI.Content.Events.Interval != null){
                window.clearInterval(GUI.Content.Events.Interval);
                GUI.Content.Events.Interval = null;
            }
            GUI.preview.show(sender);
        } else GUI.preview.closePreview(sender.findname("PreviewCloseText"+sender.Name.substr(4)));
    } else if(sender.Name.substring(0,8) == "news_img"){
        var entrynumber = (sender.Name.substring(0,8) != "news_img") ? sender.Name.substr(4) : sender.Name.substr(9);
        var linkURL = MSNWidget.preview_link[entrynumber];
        if(linkURL.indexOf('?') != -1)linkURL += "&ocid="+ocid;
        else linkURL += "?ocid="+ocid;
        window.open(linkURL);
    }
}

//Wenn auf den "Mehr-lesen" Link geklickt wurde, den Browser öffnen
GUI.Content.Events.handleMouseMoreDown = function(sender, eventArgs) {
    var counter = sender.Name.substr(15);
    var linkURL = sender.findName("Link"+counter).Text;
        if(linkURL.indexOf('?') != -1)linkURL += "&ocid="+ocid;
        else linkURL += "?ocid="+ocid;
        window.open(linkURL);
}

GUI.Content.Events.handleMouseLeave = function(sender, eventArgs){
    SearchBar.looseFocus(sender, null);
}

//Die Newseintrge einblenden
GUI.Content.Events.fadeNewsIn = function() {

    var root = MSNWidget.root;
    root.findName("NewsItems").Visibility = "Visible";

    if(!MSNWidget.platformConnector.isDocked() && root.findName("NewsImgIn0") != null) {
        
        //Falls das erste Bild noch nicht vollständig geladen wurde, Funktionsaufruf verschieben
        if(root.findName("news_img_0").Height == 0){
            window.setTimeout(function(){GUI.Content.Events.fadeNewsIn();}, 100);
            return;
         }
         
         GUI.Content.Events.locked = false;
         
        var ratio = root.findName("news_img_0").Height / root.findName("news_img_0").Width;
        var news_img = root.findName("news_img_0");
        root.findName("news_img_refl_0")["Canvas.Top"] = root.findName("news_img_refl_0").Height + news_img.Height + news_img["Canvas.Top"];
        
        var animInScale = root.findName("NewsImgIn_Scale0");
        animInScale.stop();
        animInScale.Children.GetItem(3).KeyFrames.GetItem(0).value = 25 + (150*ratio) + (150*ratio) + 25;
        animInScale.Children.GetItem(3).KeyFrames.GetItem(1).value = (100*ratio) + (100*ratio);
        
        var animIn = root.findName("NewsImgIn0");
        animIn.begin();
        
        animInScale.begin();
    }
    
    if(root.findName("Text0") == null)return;
    root.findName("Text0").Foreground = config.news.hl_color_focus;
            
    if(MSNWidget.platformConnector.flyoutShow())
        Flyout.addContentToFlyout();

    var animation = root.findName("NewsIn");
    animation.Begin();
    
    if(GUI.Content.Events.Interval != null)
        window.clearTimeout(GUI.Content.Events.Interval);
    GUI.Content.Events.Interval = window.setTimeout("GUI.Content.Events.cycleNews()", config.news.cycletime);
  }
  
//Die Videoeintrge einblenden
GUI.Content.Events.fadeVideoIn = function() {

    var sender = MSNWidget.root;
    sender.findName("NewsItems").Visibility = "Visible";
    
    //Check if there are really news available
    if(sender.findName("NewsItems").children.count == 0)return;
    
    if(!MSNWidget.platformConnector.isDocked() && sender.findName("preview_0") != null) {
        
        for(var i = 0; i < sender.findName("VideoBar").Children.Count; i++){
            if(sender.findName("preview_img_"+i).Height == 0){
                window.setTimeout(function(){GUI.Content.Events.fadeVideoIn(sender);}, 100);
                return;
             } else {
                sender.findName("preview_img_refl_"+i)["Canvas.Top"] = sender.findName("preview_img_refl_"+i).Height + sender.findName("preview_img_"+i).Height + sender.findName("preview_img_"+i)["Canvas.Top"];
             }
         }
         
        ratio = sender.findName("preview_img_0").Height / sender.findName("preview_img_0").Width;
        news_img = sender.findName("preview_img_0");
        sender.findName("preview_img_refl_0")["Canvas.Top"] = sender.findName("preview_img_refl_0").Height + news_img.Height + news_img["Canvas.Top"];
        sender.findName("preview_img_play_0").Visibility = "Visible";
        
        animInScale = sender.findName("VideoImgIn_Scale0");
        animInScale.stop();
        animInScale.Children.GetItem(5).KeyFrames.GetItem(0).value = (40*ratio) + (40*ratio);
        animInScale.Children.GetItem(5).KeyFrames.GetItem(1).value = -117 + (100*ratio) + (100*ratio);
        
        animIn = sender.findName("VideoImgIn0");
        animIn.begin();
        
        animInScale.begin();
    }
    
    if(MSNWidget.platformConnector.flyoutShow())
        Flyout.addContentToFlyout();

    var animation = sender.findName("NewsIn");
    animation.Begin();
  }
  
 //Die neuen Bilder anzeigen
 restore_img = function(sender, eventArgs) {
 
        var img = sender.findName(sender.Children.getItem(0)["Storyboard.TargetName"]);
        var img_refl = sender.findName(sender.Children.getItem(2)["Storyboard.TargetName"]);
        
        if(img == null)return;
        
        img.Opacity = 0;
        img["Canvas.Top"] = -900;
        img.Width = 100;
        img.Opacity = 1;
        
        img_refl.Opacity = 0;
        img_refl["Canvas.Top"] = -900;
        img_refl.Width = 100;
        img_refl.Opacity = 1;
   }
   
//DIe Reflektion richtig adjustieren
GUI.Content.Events.adjust_refl = function(counter) {
    if(MSNWidget.platformConnector.isDocked())return;
    var news_img = MSNWidget.root.findName("news_img"+counter);
    MSNWidget.root.findName("news_img_refl"+counter)["Canvas.Top"] = MSNWidget.root.findName("news_img_refl"+counter).Height + news_img.Height + news_img["Canvas.Top"];
  }
  
//Wird aufgerufen, sobald ein Bild fertig downgeloaded wurde
GUI.Content.Events.downloader = function(sender, counter){
  
    if(MSNWidget.downloaded_images > MSNWidget.total_images)return;
  
    MSNWidget.downloaded_images++;
    var root = MSNWidget.root;
    
    if(sender != null && root.findName("news_img_"+counter) != null) {
        root.findName('news_img_'+counter).SetSource(sender, "");
        root.findName('news_img_refl_'+counter).SetSource(sender, "");
    }
   
    root.findName("Loading_Bar").Width = (root.findName("Loading_Stroke").Width - 4) * (MSNWidget.downloaded_images / MSNWidget.total_images);
    root.findName("Loading_Bar_refl").Width = (root.findName("Loading_Stroke").Width - 4) * (MSNWidget.downloaded_images / MSNWidget.total_images);

     if(MSNWidget.downloaded_images == MSNWidget.total_images) {
        root.findName("LoadingOut").begin();
        
        GUI.Content.Events.fadeNewsIn();
    }
  }

//Cycles through the active news-items  
GUI.Content.Events.cycleNews = function() {
    
    var root = MSNWidget.root;
    
    //If the weather is visible, return
    if(Weather.visible)return;
    
    //If there's currently a preview visible, abort
    if(root.findName("Preview"+MSNWidget.news) == null
        || root.findName("Preview"+MSNWidget.news).Visibility == "Visible")return;
    
    //If there is a next newsitem available, switch the focus, otherwise refresh the category
    if(root.findName("News"+(MSNWidget.news+1)) != null ){
        if(!MSNWidget.platformConnector.isDocked()){
            GUI.Content.Events.handleMouseIn_News(root.findName("News"+(MSNWidget.news+1)), null);
            GUI.Content.Events.handleMouseOut_News(root.findName("News"+MSNWidget.news), null);
        }
        else{
            GUI.Content.Events.handleMouseIn_News(root.findName("News"+(MSNWidget.news+1)), null);
            GUI.Content.Events.handleMouseOut_News(root.findName("News"+MSNWidget.news), null);
            if(MSNWidget.platformConnector.flyoutShow())
                Flyout.addContentToFlyout();
        }
    } else News.getNews(MSNWidget.newsCat);
  }
  
/**********************************************
* VIDEO
***********************************************/
  
//Wird aufgerufen, sobald ein Bild fertig downgeloaded wurde
GUI.Content.Events.downloader_video = function(sender, counter){
    MSNWidget.downloaded_images++;
    var root = MSNWidget.root;
    
    if(sender != null && root.findName("preview_img_"+counter) != null) {
      root.findName('preview_img_'+counter).SetSource(sender, "");
      root.findName('preview_img_refl_'+counter).SetSource(sender, "");
    }
   
    root.findName("Loading_Bar").Width = (root.findName("Loading_Stroke").Width - 4) * (MSNWidget.downloaded_images / MSNWidget.total_images);
    root.findName("Loading_Bar_refl").Width = (root.findName("Loading_Stroke").Width - 4) * (MSNWidget.downloaded_images / MSNWidget.total_images);
    
     if(MSNWidget.downloaded_images == MSNWidget.total_images) {
        root.findName("LoadingOut").begin();
        GUI.Content.Events.fadeVideoIn();
    }
  }
  
GUI.Content.Events.video_prsd = function(sender, eventArgs) {
    var counter = parseInt(sender.Name.substr(17));
    if(isNaN(counter))return;    
    
    var linkURL = MSNWidget.preview_link[counter];
    
    if(linkURL.indexOf('?') != -1)linkURL += "&ocid="+ocid;
    else linkURL += "?ocid="+ocid;
    window.open(linkURL);
  }
  

GUI.Content.Events.video_in = function(sender, eventArgs) {
   
    var counter = parseInt(sender.Name.substr(12));
      
    //nur bearbeiten, falls es sich nicht um den aktuellen Beitrag handelt
    if(MSNWidget.news == counter)return;
    
  var ttl = sender.findName("VideoTitle");
    ttl.Text = MSNWidget.preview_title[counter];
    
    sender.findName("VideoDesc").Text = MSNWidget.preview[counter];
    sender.findName("VideoDesc")["Canvas.Top"] = sender.findName("VideoTitle").ActualHeight + sender.findName("VideoTitle")["Canvas.Top"] + 5;
        
    if (!MSNWidget.platformConnector.isDocked()) {
        
        if(sender.findName("preview_"+MSNWidget.news)["Canvas.ZIndex"] < sender.findName("preview_"+counter)["Canvas.ZIndex"])
            sender.findName("preview_"+counter)["Canvas.ZIndex"] = sender.findName("preview_"+MSNWidget.news)["Canvas.ZIndex"] - 1;
              
        var ratio = sender.findName("preview_img_"+MSNWidget.news).Height / sender.findName("preview_img_"+MSNWidget.news).Width;
        
        var news_img = sender.findName("preview_img_"+MSNWidget.news);
        sender.findName("preview_img_refl_"+MSNWidget.news)["Canvas.Top"] = sender.findName("preview_img_refl_"+MSNWidget.news).Height + news_img.Height + news_img["Canvas.Top"];
       
        sender.findName("preview_img_play_"+counter).Visibility = "Visible";
       
        //Die "Out"-Animation auf die aktuelle Position des Bildes setzen und abspielen.
        var animOut = sender.findName("VideoImgOut"+MSNWidget.news);
        animOut.stop();
        animOut.Children.GetItem(0).KeyFrames.GetItem(0).value = sender.findName("preview_"+MSNWidget.news)["Canvas.Left"];
        animOut.Children.GetItem(0).KeyFrames.GetItem(1).value = MSNWidget.news * 55;
        animOut.begin();
        
        animOut = sender.findName("VideoImgOut_Scale"+MSNWidget.news);
        animOut.stop();
        animOut.Children.GetItem(0).KeyFrames.GetItem(0).value = sender.findName("preview_img_"+MSNWidget.news).Width;
        animOut.Children.GetItem(2).KeyFrames.GetItem(0).value = sender.findName("preview_img_"+MSNWidget.news).Width;
        animOut.Children.GetItem(1).KeyFrames.GetItem(0).value = sender.findName("preview_img_"+MSNWidget.news)["Canvas.Top"];
        animOut.Children.GetItem(3).KeyFrames.GetItem(0).value = sender.findName("preview_img_"+MSNWidget.news)["Canvas.Top"];
        animOut.Children.GetItem(4).KeyFrames.GetItem(0).value = sender.findName("preview_img_"+MSNWidget.news).Width;
        animOut.Children.GetItem(5).KeyFrames.GetItem(0).value = sender.findName("preview_img_refl_"+MSNWidget.news)["Canvas.Top"];
        animOut.Children.GetItem(5).KeyFrames.GetItem(1).value = (40*ratio) + (40*ratio); 
        animOut.begin();
        
        MSNWidget.news = counter;
            
        var animIn = sender.findName("VideoImgIn"+counter);
        animIn.Children.GetItem(0).KeyFrames.GetItem(0).value = counter * 55;
        animIn.Children.GetItem(0).KeyFrames.GetItem(1).value = -sender.findName("VideoBar")["Canvas.Left"] + 5;
        animIn.begin();
        animInScale = sender.findName("VideoImgIn_Scale"+counter);
        animInScale.stop();
        animInScale.Children.GetItem(5).KeyFrames.GetItem(0).value = (40*ratio) + (40*ratio);
        animInScale.Children.GetItem(5).KeyFrames.GetItem(1).value = -117 + (100*ratio) + (100*ratio); 
        animInScale.begin();
        
    } else {
        MSNWidget.news = parseInt(sender.Name.substr(4));
        if (MSNWidget.platformConnector.flyoutShow())
            Flyout.addContentToFlyout();
        else MSNWidget.platformConnector.flyoutShow(true);
    }
  }
  
GUI.Content.Events.video_out = function(sender, eventArgs) {
    
  }
  
/**********************************
*           VIDEO
**/  
  
GUI.Video = {};

//Schaltet die Subkategorien weiter
GUI.Video.switchVideo = function(sender, eventArgs) {
  
    var direction = "";
    if(sender.Name == "video_left_btn")
        direction = "left";
    else if(sender.Name == "video_right_btn")
        direction = "right";
        
    if(direction == "")return;
  
    var obj = MSNWidget.root.findName("VideoBar");
    var left = obj["Canvas.Left"];
    var windowWidth = MSNWidget.root.findName("NewsItemsContainer").Width;
    var maxLeft = obj.children.count * 55; 
    var cur_preview = MSNWidget.root.findName("preview_"+MSNWidget.news);
    
    //Calculate how many previews fit in the view
    var fit = Math.floor(windowWidth / 55);
    
    var move = 0;
    if(direction == "right")
        move = ( left - (fit * 55) < -(maxLeft - (fit * 55)) ) ? -(maxLeft - (fit*55)) : (left - (fit * 55));
    else if(direction == "left")
        move = (-left - (fit * 55) < 20) ? 20 : (left + (fit * 55));
               
    if(MSNWidget.root.findName("slideVideo") == null){
        var str = '<Storyboard Name="slideVideo" >';
        str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Left)" Storyboard.TargetName="VideoBar" >';
        str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0" KeySpline="0.1,0.7 0.75,1" />';
        str += '<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0" KeySpline="0.1,0.7 0.75,1" />';
        str += '</DoubleAnimationUsingKeyFrames>';
        str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="" Storyboard.TargetProperty="(Canvas.Left)" >';
        str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0" KeySpline="0.1,0.7 0.75,1" />';
        str += '<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0" KeySpline="0.1,0.7 0.75,1" />';
        str += '</DoubleAnimationUsingKeyFrames>';
        str += '</Storyboard>';
        
        var str_XAML = MSNWidget.root.getHost().content.createFromXaml(str);
        MSNWidget.root.findName("NewsItems").Resources.add(str_XAML);
    }
    var animation = MSNWidget.root.findName("slideVideo");
    var cur_left = cur_preview["Canvas.Left"];
    animation.stop();
    animation.children.getItem(0).KeyFrames.getItem(0).Value = left;
    animation.children.getItem(0).KeyFrames.getItem(1).Value = move;
    animation.children.getItem(1)["Storyboard.TargetName"] = cur_preview.Name;
    animation.children.getItem(1).KeyFrames.getItem(0).Value = cur_left;
    animation.children.getItem(1).KeyFrames.getItem(1).Value = (-move + 5 );
    if(left == move){
        //
    }
    MSNWidget.root.findName("slideVideo").begin();
   
  }
  
//GUI.Video.clicked = false;

//GUI.Video.switchVideoDocked = function(sender, eventArgs) {
//      if(clicked) return;
//      else clicked = true;
//            
//      eventArgs.Handled = true;
//      if (sender.Name == "video_right_btn") {
//        if(sender.findName("subcat"+category) == null) return;
//            category += 1;

//          News.getNews(category);
//      } else if (sender.Name == "subcat_left_btn") {
//          category -= 1;
//          News.getNewsSubcat(sender, category);
//      } 
//      GUI.Video.clicked = false;
//  }
  
/********************************************
* GUI.Bar
*********************************************/
  
  var scrollInterval;
  var sndr;
  
//Bau die Kontrollleiste auf, abjängig davon, ob das Gadget angedockt ist oder nicht
GUI.Bar.build = function(){
}

//
GUI.Bar.buildCategoriesDocked = function(){

    var root = MSNWidget.root;
    var cat_str = "";
//    for(var i = 0; i < locale.categories.length; i++){
//        cat_str = '<TextBlock Name="cat_'+locale.categories[i]+'" Foreground="#fff" Text="'+locale.categories[i]+'" />';
//    }
}

//Erstellt die einzelnen Knpfe
GUI.Bar.buildButtons = function(root) {
    
    var in_more = false;
    var count_top = 0;
    var obj_btns = root.findName("ButtonsCat"); 
    var offset = root.findName("Btn_MSN").ActualWidth;

    root.findName("btn_MSN_img").Source = config.image_str + "msn.png";
    if(MSNWidget.platformConnector.isDocked())root.findName("msn_logo").Source = config.image_str + "msn.png";
    else obj_btns["Canvas.Left"] = 0;
    
    //alte Knpfe lschen
    obj_btns.children.clear();
    root.findName("More_Container").children.clear();
    root.findName("SearchBar_More_Container").children.clear();
    
    //Build the buttons for the SearchBar-Categories and "press" the first one
    SearchBar.buildButtons();
    
    root.findName("BtnPrsd").Stop();
    if(MSNWidget.platformConnector.isDocked())
        root.findName("BtnPrsd")["Storyboard.TargetName"] = "Btn_"+locale.searchcategories_docked[0][0]+"_Prsd";
    else
        root.findName("BtnPrsd")["Storyboard.TargetName"] = "Btn_"+locale.searchcategories[0][0]+"_Prsd";
    root.findName("BtnPrsd").Begin();
    
    if(MSNWidget.platformConnector.isDocked())return;
    
    //Die richtige Reihenfolge der angedockten Buttons ermitteln
    var categories_docked = new Array();
    if(MSNWidget.platformConnector.isDocked()){
        for(var i_categories = 0; i_categories < MSNWidget.categories.length; i_categories++){
            for(var i_docked = 0; i_docked < locale.categories_docked.length; i_docked++){
                if(MSNWidget.categories[i_categories][0] == locale.categories_docked[i_docked][0]){
                    categories_docked.push(locale.categories_docked[i_docked]);
                    break;
                }
            }
        }
    }
    
    var loop = (MSNWidget.platformConnector.isDocked()) ? categories_docked : MSNWidget.categories;
    
    //Set the offset for the buttons-canvas
    obj_btns["Canvas.Left"] = 0;
    
    for(var i_loop = 0; i_loop < loop.length; i_loop++) {
        var btn_str = "";
        if (MSNWidget.platformConnector.isDocked()) {
          btn_str = '<Canvas Width="5" Height="5" Cursor="Hand" Name="Btn_' + loop[i_loop][0] + '" Canvas.Left="187" Canvas.Top="10">';
          btn_str += '<Rectangle Width="5" Height="5" RadiusX="8" RadiusY="8">';
          btn_str += '<Rectangle.Fill>';
          btn_str += '<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">';
          btn_str += '<GradientStop Color="#66FFFFFF" Offset="0"/>';
          btn_str += '<GradientStop Color="#E5FFFFFF" Offset="0.058"/>';
          btn_str += '<GradientStop Color="#44AAAAAA" Offset="0.129"/>';
          btn_str += '</LinearGradientBrush>';
          btn_str += '</Rectangle.Fill>';
          btn_str += '</Rectangle>';
          btn_str += '<Image Source="" Height="5" Canvas.Top="1" Name="Btn_'+loop[i_loop][0] + '_img" Canvas.ZIndex="2">';
          btn_str += '</Image>';
          btn_str += '<Rectangle Visibility="Visible" Name="Btn_' + loop[i_loop][0] + '_Prsd" Width="17" Height="17" RadiusX="8" RadiusY="8" Opacity="0" Canvas.ZIndex="1">';
          btn_str += '<Rectangle.Fill>';
          btn_str += '<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">';
          btn_str += '<GradientStop Color="#FF000000" Offset="0.504"/>';
          btn_str += '<GradientStop Color="#FF222222" Offset="1"/>';
          btn_str += '</LinearGradientBrush>';
          btn_str += '</Rectangle.Fill>';
          btn_str += '</Rectangle>';
          btn_str += '<Rectangle Visibility="Visible" Name="Btn_' + loop[i_loop][0] + '_Hover" Width="17" Height="17" RadiusX="8" RadiusY="8" Stroke="#FF595959" Opacity="0">';
          btn_str += '<Rectangle.Fill>';
          btn_str += '<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">';
          btn_str += '<GradientStop Color="#19FF8200" Offset="0"/>';
          btn_str += '<GradientStop Color="#FFFF8200" Offset="1"/>';
          btn_str += '<GradientStop Color="#7FFF8200" Offset="0.482"/>';
          btn_str += '</LinearGradientBrush>';
          btn_str += '</Rectangle.Fill>';
          btn_str += '</Rectangle>';
          btn_str += '</Canvas>';
      }
      else if(in_more) {
        btn_str = '<Canvas Height="25" Width="90" Cursor="Hand" Name="Btn_'+loop[i_loop][0]+'" Canvas.Top="'+ ((count_top * 25)+5)+'" Canvas.ZIndex="5">';
        btn_str += '<Rectangle Visibility="Visible" Canvas.Left="5" Name="Btn_'+loop[i_loop][0]+'_Prsd" Width="90" Height="25" Opacity="0" Canvas.ZIndex="7" Fill="#FF000000">';
      	btn_str += '</Rectangle>';
        btn_str += '<Rectangle Width="90" Canvas.Left="5" Height="25" Name="Btn_'+loop[i_loop][0]+'_Hover" Opacity="0" Canvas.ZIndex="6">';
        btn_str += '<Rectangle.Fill>';
        btn_str += '<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">';
      	btn_str += '<GradientStop Color="#19FF8200" Offset="0"/>';
      	btn_str += '<GradientStop Color="#FFFF8200" Offset="1"/>';
      	btn_str += '<GradientStop Color="#7FFF8200" Offset="0.482"/>';
        btn_str += '</LinearGradientBrush>';
        btn_str += '</Rectangle.Fill>';
        btn_str += '</Rectangle>';
        btn_str += '<Image Source="" Canvas.Left="5" Height="20" Name="Btn_'+loop[i_loop][0]+'_img" Canvas.ZIndex="8"/>';
        btn_str += '<TextBlock FontSize="8" Canvas.ZIndex="8" Canvas.Left="30" Canvas.Top="3" Foreground="#FFFFFFFF" Name="'+loop[i_loop][0]+'_txt" Text="'+loop[i_loop][0]+'" />';
        btn_str += '</Canvas>';
        count_top++;
      }
      else {
        btn_str = '<Canvas Width="60" Height="30" Cursor="Hand" Name="Btn_'+loop[i_loop][0]+'" Canvas.Left="187" Canvas.Top="2">';
        btn_str += '<Rectangle Width="60" Height="30" RadiusX="2" RadiusY="2" Stroke="#FF161616">';
        btn_str += '<Rectangle.Fill>';
        btn_str += '<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">';
      	btn_str += '<GradientStop Color="#66FFFFFF" Offset="0"/>';
      	btn_str += '<GradientStop Color="#E5FFFFFF" Offset="0.058"/>';
      	btn_str += '<GradientStop Color="#00FFFFFF" Offset="0.129"/>';
      	btn_str += '</LinearGradientBrush>';
      	btn_str += '</Rectangle.Fill>';
      	btn_str += '</Rectangle>';
      	btn_str += '<Image Source="" Height="20" Canvas.Top="2" Name="Btn_'+loop[i_loop][0]+'_img" Canvas.ZIndex="2">';
      	btn_str += '<Image.RenderTransform>';
        btn_str += '<RotateTransform  Angle="0" CenterX="8.5" CenterY="8.5" />';
        btn_str += '</Image.RenderTransform>';
        btn_str += '</Image>';
      	btn_str += '<TextBlock Height="11" FontSize="8.8" Foreground="#FFFFFFFF" Name="'+loop[i_loop][0]+'_txt" Text="'+loop[i_loop][0]+'" TextWrapping="Wrap" Canvas.Top="17" Canvas.ZIndex="2"/>';
      	btn_str += '<Rectangle Visibility="Visible" Name="Btn_'+loop[i_loop][0]+'_Prsd" Width="60" Height="30" RadiusX="2" RadiusY="2" Opacity="0" Canvas.ZIndex="1">';
      	btn_str += '<Rectangle.Fill>';
      	btn_str += '<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">';
      	btn_str += '<GradientStop Color="#FF000000" Offset="0.504"/>';
      	btn_str += '<GradientStop Color="#FF222222" Offset="1"/>';
      	btn_str += '</LinearGradientBrush>';
      	btn_str += '</Rectangle.Fill>';
      	btn_str += '</Rectangle>';
      	btn_str += '<Rectangle Visibility="Visible" Name="Btn_'+loop[i_loop][0]+'_Hover" Width="60" Height="30" RadiusX="2" RadiusY="2" Stroke="#FF595959" Opacity="0">';
      	btn_str += '<Rectangle.Fill>';
      	btn_str += '<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">';
      	btn_str += '<GradientStop Color="#19FF8200" Offset="0"/>';
      	btn_str += '<GradientStop Color="#FFFF8200" Offset="1"/>';
      	btn_str += '<GradientStop Color="#7FFF8200" Offset="0.482"/>';
      	btn_str += '</LinearGradientBrush>';
      	btn_str += '</Rectangle.Fill>';
      	btn_str += '</Rectangle>';
      	btn_str += '</Canvas>';
    	}
  
  	  var btn_XAML = root.getHost().content.createFromXAML(btn_str);
  	  btn_XAML.findName("Btn_"+loop[i_loop][0]+"_img").Source = config.image_str+loop[i_loop][0]+'.png';
  	  
  	  //Text im Button zentrieren und den gesamten Button anordnen
  	  if (!in_more && !MSNWidget.platformConnector.isDocked()) {
  	      //for the undocked main-bar
  	      btn_XAML["Canvas.Left"] = i_loop * (btn_XAML.ActualWidth + 1.5) + offset;
  	      btn_XAML.findName("Btn_"+loop[i_loop][0] + "_img")["Canvas.Left"] = (btn_XAML.Width - btn_XAML.findName("Btn_"+loop[i_loop][0] + "_img").ActualWidth) / 2 - 13;
  	      btn_XAML.findName(loop[i_loop][0] + "_txt")["Canvas.Left"] = (btn_XAML.Width - btn_XAML.findName(loop[i_loop][0] + "_txt").ActualWidth) / 2;
  	  } else if (MSNWidget.platformConnector.isDocked()) {
  	      //If the buttons is in the "more"-container
  	      btn_XAML["Canvas.Left"] = (i_loop * 19) + 12;
  	      btn_XAML.findName("Btn_"+loop[i_loop][0] + "_img")["Canvas.Left"] = (btn_XAML.Width - btn_XAML.findName("Btn_"+loop[i_loop][0] + "_img").ActualWidth) / 2 - 10;
  	      btn_XAML.findName("Btn_"+loop[i_loop][0] + "_img")["Canvas.Top"] = (btn_XAML.Height - btn_XAML.findName("Btn_"+loop[i_loop][0] + "_img").ActualHeight) / 2 + 3;
   	  } else {
        btn_XAML.findName("Btn_"+loop[i_loop][0]+"_img")["Canvas.Top"] = (25 - btn_XAML.findName("Btn_"+loop[i_loop][0]+"_img").ActualHeight)/2;
        btn_XAML.findName(loop[i_loop][0]+"_txt")["Canvas.Top"] = (25 - btn_XAML.findName(loop[i_loop][0]+"_txt").ActualHeight)/2;
      }

  	  if(in_more)obj_btns = root.findName("More_Container");
  	  
      obj_btns.children.add(btn_XAML);
      GUI.Bar.addEvents(btn_XAML);

  	  //Check if the next button fits in the bar or has to be displayed in the "more"-container
  	  if(!MSNWidget.platformConnector.isDocked())
  	  if((obj_btns["Canvas.Left"] + btn_XAML["Canvas.Left"] + (btn_XAML.ActualWidth) + 10) > 
            MSNWidget.root.findName("Buttons").Width) {
  	             in_more = true;
  	          }

	  }	  
	 
    //Den Button der aktuellen Kategorie "drücken"
    root.findName("Btn_"+News.getCategory()+"_Prsd").Opacity = 1;
	  
    //Die Hhe des einstellen
    root.findName("More_Bg2")["Height"] = (count_top * 25) + 10;
    root.findName("More_Bg")["Height"] = (count_top * 25);

    root.findName("SearchBar_Download").children.add(root.getHost().content.createFromXAML('<Image Canvas.Top="2" Canvas.Left="2" Source="' + config.image_str + 'download.png" Width="16" />'));
    root.findName("SearchBar_Options").children.add(root.getHost().content.createFromXAML('<Image Canvas.Top="2" Canvas.Left="2" Source="' + config.image_str + 'options.png" Width="16" />'));
    root.findName("SearchBar_Usage").children.add(root.getHost().content.createFromXAML('<Image Canvas.Top="2" Canvas.Left="2" Source="' + config.image_str + 'faq.png" Width="16" />'));    
}

//Schaltet die Subkategorien weiter
GUI.Bar.switchSubCats = function(sender, eventArgs) {
      var sndr = sender;
      
      if(scrollInterval == null)
        scrollInterval = window.setInterval(function(){GUI.Bar.scrollSubCat(sndr, eventArgs);},10);
  }
  
//Schaltet die Subkategorien im angedockten Zustand weiter
GUI.Bar.switchSubCatsDocked = function(sender, eventArgs) {
      if(GUI.Content.Events.locked)return;
      GUI.Content.Events.locked = true;
            
      var category = MSNWidget.newsCat;
      if (sender.Name == "subcat_right_btn") {
        if(sender.findName("subcat"+category) == null) return;
          category += 1;
          News.getNewsSubcat(MSNWidget.root.findName("subcat"+category), eventArgs);
      } else if (sender.Name == "subcat_left_btn") {
        if(sender.findName("subcat"+category) == null) return;
          category -= 1;
          News.getNewsSubcat(MSNWidget.root.findName("subcat"+category), eventArgs);
      }
      GUI.buildSubcats(MSNWidget.root, category);
  }
  
GUI.Bar.scrollSubCat = function(sender, eventArgs) {
    var obj = sender.findName("SubCats");

    sender.findName("subcat_left_btn").Visibility = "Visible";
    sender.findName("subcat_right_btn").Visibility = "Visible";
    
    var lastChild = obj.children.getItem(obj.children.count - 1);
    
    if(sender.Name == "subcat_left_btn") {
    	if(obj["Canvas.Left"] <= 0) {
          obj["Canvas.Left"] += 2;
        }
        else {
            sender.findName("subcat_left_btn").Visibility = "Collapsed";
            window.clearInterval(scrollInterval);
            scrollInterval = null;
          return;
        }
      } else {
      if((lastChild["Canvas.Left"] + lastChild.ActualWidth - Math.abs(obj["Canvas.Left"])) < (obj.Width) ) {
          sender.findName("subcat_right_btn").Visibility = "Collapsed";
          window.clearInterval(scrollInterval);
          scrollInterval = null;
         } else obj["Canvas.Left"] -= 2;
      }
  }
  
  GUI.Bar.stopSubCats = function(sender) {
   window.clearInterval(scrollInterval);
   scrollInterval = null;
  }
  
/* In the docked state, this function switches the main categories
*/
GUI.Bar.switchMainCat = function(sender, eventArgs){
    
    if(GUI.Content.Events.locked)return;
    else GUI.Content.Events.locked = true;

    var oldIndex = News.getCategoryIndex();
    var newIndex = 0;
    var animation = sender.findName("scrollMainCat");
    animation.stop();
    if(sender.Name == "subcat_main_left_btn"){
        if(oldIndex == 0)return;
        newIndex = oldIndex - 1;        
    } else if(sender.Name == "subcat_main_right_btn"){
        if(oldIndex == locale.categories.length - 1)return;
        
        newIndex = oldIndex + 1;
    }
    
    sender.findName("subcat_text2").Text = News.getCategory();
    sender.findName("subcat_text").Text = News.getCategory(News.getCategoryCode(newIndex));
    if(newIndex > oldIndex){
        animation.children.getItem(0).keyframes.getItem(0).Value = 300;
        animation.children.getItem(1).keyframes.getItem(1).Value = -300;
    } else {
        animation.children.getItem(0).keyframes.getItem(0).Value = -300;
        animation.children.getItem(1).keyframes.getItem(1).Value = 300;
    }
    var actleft = sender.findName("innerSubcat")["Canvas.Left"];
    var newleft = (sender.findName("subcat").getParent().Width / 2) - (sender.findName("subcat_text").ActualWidth / 2);
    animation.children.getItem(2).keyframes.getItem(0).Value = actleft;
    animation.children.getItem(2).keyframes.getItem(1).Value = newleft;
    
    //Check the visibility for the arrows
    GUI.Bar.checkArrows(newIndex);
    
    animation.begin();
    MSNWidget.newsCat = (News.getCategoryCode(newIndex));
    GUI.buildSubcats(MSNWidget.root, MSNWidget.newsCat);
    News.getNews(MSNWidget.newsCat);
}

GUI.Bar.checkArrows = function(index){
    
    if(!MSNWidget.platformConnector.isDocked() || Weather.visible){
        MSNWidget.root.findName("subcat_main_right_btn").Visibility = "Collapsed";
        MSNWidget.root.findName("subcat_main_left_btn").Visibility = "Collapsed";
        return;
    }

    if(index == 0){
        MSNWidget.root.findName("subcat_main_left_btn").Visibility = "Collapsed";
        MSNWidget.root.findName("subcat_main_right_btn").Visibility = "Visible";
    } else if(index == MSNWidget.categories.length - 1){
        MSNWidget.root.findName("subcat_main_right_btn").Visibility = "Collapsed";
        MSNWidget.root.findName("subcat_main_left_btn").Visibility = "Visible";
    } else {
         MSNWidget.root.findName("subcat_main_right_btn").Visibility = "Visible";
         MSNWidget.root.findName("subcat_main_left_btn").Visibility = "Visible";
    }
}
  
  /*********************************************
  * Preview-News
  *********************************************/
  GUI.preview = {};
  
  //Zeigt die preview zu den News an
  GUI.preview.show = function(sender) {
    GUI.Content.Events.locked = true;
    var root = MSNWidget.root;
    
    //Den Newscycle anhalten
    if(GUI.Content.Events.Interval != null)
        window.clearTimeout(GUI.Content.Events.Interval);
        
    GUI.Content.Events.Interval = null;
    
    //Als erstes Herausfinden, wohin die "NewsItems" animiert werden müssen
    var animation = root.findName("NewsMove");
    animation.stop();
    animation.Children.GetItem(0).KeyFrames.GetItem(0).value = 0;
    animation.Children.GetItem(0).KeyFrames.GetItem(1).value = -1 * (sender["Canvas.Top"] - 20);
    animation.begin();
    
    var counter = sender.Name.substr(4);
    
    //Start the "mouse-out"-effect
    GUI.Content.Events.locked = true;
    animation = MSNWidget.root.findName("BtnHoverOut");
    animation.stop();
    animation["StoryBoard.TargetName"] = 'News_canvas'+counter+'_Hover' ;
    animation.begin();
        
    var i = 0;
    var str = "";
    var obj = null;
    while(root.findName("News"+i) != null) {
        
        //Der bearbeitete Newseintrag
        var news = root.findName("Text"+i);
        
        var line = root.findName("Line"+i);
        if(line != null){
            line.Visibility = "Collapsed";
        }
        
        if(i < counter) {
            root.findName("News"+i).Visibility = "Collapsed";
            i++;
            continue;
        }
        if(i == counter) {
            news.Text = MSNWidget.preview_title[counter].replace(/&amp;/g, "&");
            news.TextWrapping = "Wrap";
            news.Foreground = "#fff";
            str = '<Storyboard Name="slideMain'+i+'" Completed="deleteSelf">';
            str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="FontSize" Storyboard.TargetName="Text'+i+'" >';
            str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="9" />';
            str += '<SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="9" />';
            str += '</DoubleAnimationUsingKeyFrames>';
            str += '</Storyboard>';
            obj = root.getHost().content.createFromXaml(str);
            if(root.findName("slideMain"+i) == null)
                root.findName("News"+i).Resources.add(obj);
            else obj = root.findName("slideMain"+i);
            obj.Begin();
            i++;
            continue;
        }
            
        //Fire-and-forget-Animtionen erstellen
        str = '<Storyboard Name="slideNews'+i+'" Completed="deleteSelf">';
        str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Top)" Storyboard.TargetName="News'+i+'" >';
        str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="'+news.getParent()["Canvas.Top"]+'" />';
        str += '<SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="'+(root.findName("SearchBar")["Canvas.Top"] + sender["Canvas.Top"])+'" />';
        str += '</DoubleAnimationUsingKeyFrames>';
        str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="News'+i+'" >';
        str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1" />';
        str += '<SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="0" />';
        str += '</DoubleAnimationUsingKeyFrames>';
        if(root.findName("Line"+i) != null){
            str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Top)" Storyboard.TargetName="Line'+i+'" >';
            str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="'+news.getParent()["Canvas.Top"]+'" />';
            str += '<SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="'+(root.findName("SearchBar")["Canvas.Top"] + sender["Canvas.Top"])+'" />';
            str += '</DoubleAnimationUsingKeyFrames>';
            str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Line'+i+'" >';
            str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1" />';
            str += '<SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="0" />';
            str += '</DoubleAnimationUsingKeyFrames>';
        }
        str += '</Storyboard>';
        obj = root.getHost().content.createFromXaml(str);
        if(root.findName("slideNews"+i) == null)
                root.findName("News"+i).Resources.add(obj);
        else obj = root.findName("slideNews"+i);
        obj.Begin();
        
        i++;
    }
    
     
    //Die eigentliche Preview anzeigen
    if(!MSNWidget.platformConnector.isDocked()){
        var preview = sender.findName("Preview" + sender.Name.substr(4));   
        preview.Opacity = 0;
        preview.Visibility = "Visible";
        preview["Canvas.Top"] = sender["Canvas.Top"] + sender.findName("Text"+sender.Name.substr(4))["Canvas.Top"] + sender.findName("Text"+sender.Name.substr(4)).ActualHeight + 5;
        preview["Canvas.ZIndex"] = 8;
      }
      
    MSNWidget.platformConnector.makePageView(counter);
    
  }
  
  //Schließt die Vorschauansicht wieder und kehrt zur Übersicht zurück
  GUI.preview.closePreview = function(sender, eventArgs) {
    var counter = parseInt(sender.Name.substr(16));
    if(isNaN(counter))return;
    var root = MSNWidget.root;
    var canv_top = root.findName("News0")["Canvas.Top"];
    var str = "";
    var obj = null;
    
    //Als erstes Herausfinden, wohin die "NewsItems" animiert werden müssen
    var animation = root.findName("NewsMove");
    animation.Children.GetItem(0).KeyFrames.GetItem(0).value = root.findName("NewsItems")["Canvas.Top"];
    animation.Children.GetItem(0).KeyFrames.GetItem(1).value = 0;
    animation.begin();
    
    var i = 0;
    while(root.findName("Preview"+i) != null) {
    
        var news = root.findName("Text"+i);
        root.findName("News"+i).Visibility = "Visible";
        
        var line = root.findName("Line"+i);
        if(line != null){
            line.Visibility = "Visible";
        }
        
        if(i < counter) {
            i++;
            continue;
        }
        if(i == counter){
            var preview = root.findName("Preview"+i);
            
            preview.Visibility = "Collapsed";
            preview.Opacity = 0;
            news.TextWrapping = "NoWrap";
            news.Text = News.trim(news, root.findName("NewsItems").Width - 15 );
            str = '<Storyboard Name="slideNews'+i+'" Completed="deleteSelf">';
            str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="FontSize" Storyboard.TargetName="Text'+i+'" >';
            str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="9" />';
            str += '<SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="9" />';
            str += '</DoubleAnimationUsingKeyFrames>';
            str += '</Storyboard>';
            obj = root.getHost().content.createFromXaml(str);
            if(root.findName("slideNews"+i) == null)
                root.findName("News"+i).Resources.add(obj);
            else obj = root.findName("slideNews"+i);
            obj.Begin();
            news.TextWrapping = "NoWrap";
            i++;
           
            continue;
        }
        
        //Fire-and-forget-Animtionen erstellen
        str = '<Storyboard Name="slideNews'+i+'" Completed="deleteSelf">';
        str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Top)" Storyboard.TargetName="News'+i+'" >';
        str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="'+root.findName("News"+i)["Canvas.Top"]+'" />';
        str += '<SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="'+((i * config.news.height)+canv_top)+'" />';
        str += '</DoubleAnimationUsingKeyFrames>';
        str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="News'+i+'" >';
        str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0" />';
        str += '<SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="1" />';
        str += '</DoubleAnimationUsingKeyFrames>';
        if(root.findName("Line"+i) != null){
            str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Top)" Storyboard.TargetName="Line'+i+'" >';
            str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="'+root.findName("Line"+i)["Canvas.Top"]+'" />';
            str += '<SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="'+(((i+1) * config.news.height)+canv_top)+'" />';
            str += '</DoubleAnimationUsingKeyFrames>';
            str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Line'+i+'" >';
            str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0" />';
            str += '<SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="1" />';
            str += '</DoubleAnimationUsingKeyFrames>';
        }
        str += '</Storyboard>';
        obj = root.getHost().content.createFromXaml(str);
        if(root.findName("slideNews"+i) == null)
                root.findName("News"+i).Resources.add(obj);
            else obj = root.findName("slideNews"+i);
        obj.Begin();
        i++;
    }
    
    //Den NewsCycle wieder in Gang setzen
    if(GUI.Content.Events.Interval != null)
        window.clearTimeout(GUI.Content.Events.Interval);
        
    GUI.Content.Events.Interval = window.setTimeout("GUI.Content.Events.cycleNews()", config.news.cycletime);
    
  }
  
  var animCompleted = function(sender, eventArgs) {
    GUI.Content.Events.locked = false;
  }
  
function hideSelf(sender, eventArgs){
    MSNWidget.root.findName(sender["Storyboard.TargetName"]).Visibility = "Collapsed";
}

function deleteSelf(sender, eventArgs) {
    var obj = null;
    
    //Falls der Auslöser eine Einblende-Animation war, den zugehörigen Preview einblenden
    if(sender.Name.substring(0,9) == "slideMain"){
        var str = '<Storyboard Name="showPrevi'+sender.Name.substr(9)+'" Completed="deleteSelf">';
        str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Preview'+sender.Name.substr(9)+'" >';
        str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0" />';
        str += '<SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="1" />';
        str += '</DoubleAnimationUsingKeyFrames>';
        str += '</Storyboard>';
        var obj = MSNWidget.root.getHost().content.createFromXaml(str);
        MSNWidget.root.findName("News"+sender.Name.substr(9)).Resources.add(obj);
        obj.Begin();
    }
  
    obj = MSNWidget.root.findName("News"+sender.Name.substr(9));
    if(obj == null)return;
    obj.Visibility = (obj.Opacity < 1) ? "Collapsed" : "Visible";
    obj.Resources.remove(sender);
  }
  

  //Baut die GUI am Anfang und bei einer Größenänderung neu auf
  GUI.update = function() {
  
      var rootElement = MSNWidget.root;
      var pageWidth = document.getElementById("MSNSilverlight").offsetWidth;
      var pageHeight = document.getElementById("MSNSilverlight").offsetHeight;
      var scrollWidth = 10;
      GUI.Bar.inkBar(rootElement);

      var opac = "Visible";
      if (MSNWidget.platformConnector.isDocked()) {
        opac = "Collapsed";
      }
      
      GUI.Bar.checkArrows(News.getCategoryIndex());

      rootElement.findName("Btn_MSN").Visibility = opac;
      rootElement.findName("Btn_More").Visibility = opac;
      rootElement.findName("NewsImage").Visibility = opac;      
            
      rootElement.findName("MSN-Startseite").Visibility = (MSNWidget.platformConnector.isDocked()) ? "Visible" : "Collapsed";
    
      rootElement.findName("Loading_Stroke").Width = pageWidth * 0.8;
      rootElement.findName("Loading_Stroke_refl").Width = pageWidth * 0.8; 
      rootElement.findName("Loading")["Canvas.Left"] = (rootElement.findName("NewsItems_Bg").Width - rootElement.findName("Loading_Stroke").ActualWidth)/2;
      rootElement.findName("Loading")["Canvas.Top"] = (rootElement.findName("NewsItems_Bg").Height - rootElement.findName("Loading").Height)/2;
        
      rootElement.findName("BgClip").Rect = "0,0,"+(pageWidth-3)+","+(pageHeight-3);
      rootElement.findName("Content")["Width"] = pageWidth;
      rootElement.findName("Content")["Height"] = pageHeight;
      rootElement.findName("Page_BG")["Width"] = pageWidth;
      rootElement.findName("Page_BG")["Height"] = pageHeight;
      rootElement.findName("Bar_Reflektion")["Width"] = pageWidth - rootElement.findName("smallWeather").Width;
      rootElement.findName("BarBg")["Width"] = pageWidth;
      rootElement.findName("Buttons")["Width"] = pageWidth - rootElement.findName("Btn_MSN").Width - rootElement.findName("smallWeather").Width;
      rootElement.findName("NewsItems")["Canvas.Left"] = (MSNWidget.platformConnector.isDocked()) ? 5 : 122;
      rootElement.findName("NewsItems")["Width"] = pageWidth - rootElement.findName("NewsItems")["Canvas.Left"] - 2;
      rootElement.findName("NewsItemsContainer")["Width"] = pageWidth - 10;
      rootElement.findName("NewsItems_Bg")["Width"] = pageWidth  -10;
      
      
      var cnt_height = (MSNWidget.platformConnector.isDocked()) ? (pageHeight - rootElement.findName("Bar").Height - 30) : (pageHeight - rootElement.findName("Bar").Height - 35);
      rootElement.findName("NewsItems_Bg").Height = cnt_height;
      rootElement.findName("NewsItemsContainer").Height = cnt_height;
      rootElement.findName("NewsItemsContainerClip")["Rect"] = "0,20,"+rootElement.findName("NewsItemsContainer").Width+","+(cnt_height-20);
      rootElement.findName("NewsItems")["Height"] = cnt_height; 
      rootElement.findName("Content")["Canvas.Top"] = (MSNWidget.platformConnector.isDocked()) ? 50 : 55;
      
      if(MSNWidget.platformConnector.isDocked()){
        rootElement.findName("subcat_text").FontSize = 16;
        rootElement.findName("subcat_text2").FontSize = 16;
        rootElement.findName("innerSubcat")["Canvas.Left"] = (rootElement.findName("subcat").getParent().Width / 2) - (rootElement.findName("subcat_text").ActualWidth / 2);
        rootElement.findName("subcat_main_right_btn")["Canvas.Left"] = pageWidth - 8;
      } else {
        rootElement.findName("subcat_text").FontSize = 20;
        rootElement.findName("subcat_text2").FontSize = 20;
        rootElement.findName("innerSubcat")["Canvas.Left"] = 12;
      }
      rootElement.findName("subcat_text_Hover").Width = rootElement.findName("subcat_text").ActualWidth;
      rootElement.findName("subcat_text_Hover").Height = rootElement.findName("subcat_text").ActualHeight;
      rootElement.findName("Subcat_Scroll")["Width"] = rootElement.findName("NewsItems_Bg")["Width"];
     
      rootElement.findName("Subcat_Clip")["Rect"] = "15,15,"+(rootElement.findName("Subcat_Scroll").ActualWidth-30)+",-15";
      rootElement.findName("subcat_right_btn")["Canvas.Left"] = rootElement.findName("Subcat_Scroll")["Width"] - rootElement.findName("subcat_right_btn").ActualWidth;
      rootElement.findName("SubCats_bg").Width = rootElement.findName("Subcat_Scroll").Width;
      rootElement.findName("SubCats_bg_black").Width = rootElement.findName("Subcat_Scroll").Width;
      rootElement.findName("SubCats").Width = rootElement.findName("Subcat_Scroll").ActualWidth-30;
      
      //Small Weather
      rootElement.findName("smallWeather")["Canvas.Left"] = pageWidth - rootElement.findName("smallWeather").Width;
      
      //Suchleiste je nach Status anpassen
      if(!MSNWidget.platformConnector.isDocked()){          
          rootElement.findName("Bar_Reflektion").Opacity = 1;
          rootElement.findName("BarBg").Opacity = 1;
          rootElement.findName("Btn_More")["Canvas.Left"] = pageWidth - 15 - rootElement.findName("smallWeather").Width;
          rootElement.findName("More")["Canvas.Left"] = pageWidth - rootElement.findName("More").ActualWidth - 15;
      }else{
          rootElement.findName("Bar_Reflektion").Opacity = 0;
          rootElement.findName("BarBg").Opacity = 0;
      }
      SearchBar.resize();
      Weather.resize();
      GUI.Bar.build();
      GUI.Bar.buildButtons(rootElement);
  }
  
GUI.showOptions = function(sender, eventArgs) {
    
    News.clearNews();
    GUI.update();
    
    //Clear the interval if its running
    if(GUI.Content.Events.Interval != null){
        window.clearInterval(GUI.Content.Events.Interval);
        GUI.Content.Events.Interval = null;
    }
    
    sender.findName("NewsItems")["Canvas.Left"] = 10;
    
    var offset = (sender.findName("NewsItems_Bg").ActualWidth - 220)/2;
    sender.findName("NewsItems").children.add(sender.getHost().content.createFromXaml(
      '<TextBlock Foreground="#ffddddff" Canvas.Top="25" Canvas.Left="15" Text="Eine neue Hintergrundfarbe auswaehlen:" />')
    );    
  
    for(var i = 0; i < config.bg_color.length; i++){
        var color_btn = '<Canvas Name="'+i+'" Width="50" Height="30" Canvas.Left="'+(offset + (i%4)*55)+'" Canvas.Top="'+(55+(Math.floor(i/4)*34))+'" Cursor="Hand">';
        color_btn += '<Rectangle Width="50" Height="30" Fill="'+config.bg_color[i]+'" RadiusX="2" RadiusY="2" />';
        color_btn += '<Rectangle Width="50" Height="30" RadiusX="2" RadiusY="2" Stroke="#777777">';
        color_btn += '<Rectangle.Fill>';
        color_btn +=	'<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">';
        color_btn +=	'<GradientStop Color="#7F'+config.bg_color2[i]+'" Offset="0"/>';
        color_btn +=	'<GradientStop Color="#99'+config.bg_color2[i]+'" Offset="0.134"/>';
        color_btn +=	'<GradientStop Color="#7F'+config.bg_color2[i]+'" Offset="0.299"/>';
        color_btn +=	'<GradientStop Color="#26'+config.bg_color2[i]+'" Offset="0.562"/>';
        color_btn +=	'<GradientStop Color="#66'+config.bg_color2[i]+'" Offset="0.496"/>';
        color_btn +=	'<GradientStop Color="#26000000" Offset="0.8"/>';
        color_btn +=	'<GradientStop Color="#66000000" Offset="1"/>';
        color_btn +=	'</LinearGradientBrush>';
        color_btn +=	'</Rectangle.Fill>';
        color_btn += '</Rectangle>';
        color_btn += '</Canvas>';
  		
  		var color_btn_obj = sender.getHost().content.createFromXaml(color_btn);
  		sender.findName("NewsItems").children.add(color_btn_obj);

  		color_btn_obj.addEventListener("MouseLeftButtonDown", GUI.setColor);
    }
    
    //Add the "close"-Buttons
    var close_btn = '<Canvas Name="PreviewCloseText'+i+'" Canvas.Top="2" Width="10" Height="10" Cursor="Hand" >';
    close_btn += '<Line X1="2" Y1="2" X2="8" Y2="8" Stroke="#ddd" StrokeThickness="0.5" Cursor="Hand" />';
    close_btn += '<Line X1="2" Y1="8" X2="8" Y2="2" Stroke="#ddd" StrokeThickness="0.5" Cursor="Hand" />';
    close_btn += '<Rectangle Height="10" Width="10" RadiusX="1" Fill="#03000000" RadiusY="1" Stroke="#ddd" Cursor="Hand" StrokeThickness="0.5" /></Canvas>';
    
    var close_btn_obj = sender.getHost().content.createFromXaml(close_btn);
    close_btn_obj["Canvas.Top"] = 25;
    close_btn_obj["Canvas.Left"] = sender.findName("NewsItemsContainer").Width - 32;
    close_btn_obj.addEventListener("MouseLeftButtonDown", GUI.hideOptions);
    sender.findName("NewsItems").children.add(close_btn_obj);
  }
  
GUI.hideOptions = function(sender, eventArgs){
    GUI.update();
    News.getNews(MSNWidget.newsCat);
}

    
GUI.showDownload = function(sender, eventArgs) {
    News.clearNews();
    GUI.update();
    
    sender.findName("NewsItems").children.add(sender.getHost().content.createFromXaml(
      '<TextBlock Canvas.Top="40" Width="350" Canvas.Left="-100"  Text="'+locale.getToolbar +'" TextWrapping="Wrap" Foreground="#ddd" FontSize="10" />'
    ));
    sender.findName("NewsItems").children.add(sender.getHost().content.createFromXaml(
      '<Canvas Name="Dld_Btn" Canvas.Top="80" Canvas.Left="-100" Width="200" Height="50" Cursor="Hand">'
      +'<Rectangle RadiusX="5" RadiusY="5" Width="200" Height="50" Fill="#FF000000" Name="DldBg"  />'
			+'<Rectangle RadiusX="5" RadiusY="5" Width="200" Height="50" Name="Dld_Reflektion" >'
			+'	<Rectangle.Fill>'
			+'		<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">'
			+'			<GradientStop Color="#7FFFFFFF" Offset="0" />'
			+'			<GradientStop Color="#99FFFFFF" Offset="0.134" />'
			+'			<GradientStop Color="#7FFFFFFF" Offset="0.299" />'
			+'			<GradientStop Color="#26FFFFFF" Offset="0.562" />'
			+'			<GradientStop Color="#66FFFFFF" Offset="0.496" />'
			+'			<GradientStop Color="#26FFFFFF" Offset="1" />'
			+'		</LinearGradientBrush>'
			+'	</Rectangle.Fill>'
			+'</Rectangle>'
			+'<TextBlock Name="Dld_Txt" Text="Kostenfrei herunterladen!" Foreground="#FFFFFF" />'
      +'</Canvas>'
    ));
    
    sender.findName("Dld_Txt")["Canvas.Left"] = (sender.findName("Dld_Btn").ActualWidth - sender.findName("Dld_Txt").ActualWidth)/2;
    sender.findName("Dld_Txt")["Canvas.Top"] = (sender.findName("Dld_Btn").ActualHeight - sender.findName("Dld_Txt").ActualHeight)/2;
    sender.findName("Dld_Btn")["Canvas.Left"] = ((sender.findName("NewsItems").ActualWidth + sender.findName("NewsItems")["Canvas.Left"] - sender.findName("Dld_Btn").ActualWidth)/2) - sender.findName("NewsItems")["Canvas.Left"];
 
    sender.findName("Dld_Btn").addEventListener("MouseLeftButtonDown", function(){window.open("http://www.msn.de/toolbar/");});
  }
  
GUI.showUsage = function(sender, eventArgs) {
News.clearNews();
GUI.update();

sender.findName("NewsItems").children.add(sender.getHost().content.createFromXaml(
  '<TextBlock Name="Usage_Txt" Canvas.Top="40" Width="350" Canvas.Left="-100"  Text="'+locale.usage +'" TextWrapping="Wrap" Foreground="#ddd" FontSize="10" />'
));


//sender.findName("Usage_Txt")["Canvas.Left"] = (sender.findName("Content").ActualWidth - sender.findName("Usage_Txt").ActualWidth)/2;
//sender.findName("Usage_Txt")["Canvas.Top"] = (sender.findName("Content").ActualHeight - sender.findName("Usage_Txt").ActualHeight)/2;

}
  
GUI.setColor = function(sender, eventArgs) {
    MSNWidget.platformConnector.saveSettings("bgColor", sender.Name);
    GUI.Bar.inkBar();
}

GUI.Bar.inkBar = function() {
    var choice = MSNWidget.platformConnector.loadSettings("bgColor");
    if(choice == false)choice = 0;
    var barBgReflection = MSNWidget.root.findName("Bar_Reflektion");
    var barBg = MSNWidget.root.findName("BarBg");
    var bg = MSNWidget.root.findName("Page_BG");

    barBg.Fill.Color = config.bg_color[choice];
    bg.Fill.Color = config.bg_color[choice];
    barBgReflection.Fill.GradientStops.GetItem(0).Color = "#9F" + config.bg_color2[choice];
    barBgReflection.Fill.GradientStops.GetItem(1).Color = "#D9" + config.bg_color2[choice];
    barBgReflection.Fill.GradientStops.GetItem(2).Color = "#AF" + config.bg_color2[choice];
    barBgReflection.Fill.GradientStops.GetItem(3).Color = "#56" + config.bg_color2[choice];
    barBgReflection.Fill.GradientStops.GetItem(4).Color = "#16" + config.bg_color2[choice];
    barBgReflection.Fill.GradientStops.GetItem(5).Color = "#36" + config.bg_color2[choice];

}

  //Blendet zu jedem Button die passenden Unterkategorie-Buttons ein
  GUI.buildSubcats = function(root, cat) {
    
    var subcats = new Array();
    var canv_subcats = root.findName("SubCats");
    canv_subcats.children.clear();
    canv_subcats["Canvas.Left"]=0;
    root.findName("subcat_right_btn").Visibility = "Collapsed";
    root.findName("subcat_left_btn").Visibility = "Collapsed";
    
    var maincat = Math.floor(cat/100)*100;
    var alt_maincat = Math.floor(cat/100) - 1;
    for(var x = 0; x <  locale.subcats[alt_maincat].length; x++){
        subcats.push(locale.subcats[alt_maincat][x][0]);
    }
   
    var canv_subcats = root.findName("SubCats");
    var control = root.getHost();
    var width_all = 25;

    for (var i = 0; i < subcats.length; i++) {

            var cat_ext = maincat + i;
            var subcat_str = '<TextBlock Text="' + subcats[i] + '" FontSize="10" ';
            subcat_str += (MSNWidget.platformConnector.isDocked()) ? '' : ' Cursor="Hand" ';
            subcat_str += ' Name="subcat' + cat_ext + '" Foreground="#FFcccccc" Canvas.Left="' + width_all + '" Canvas.Top="3" />';
            subcat = control.content.createFromXAML(subcat_str);
            width_all += subcat.ActualWidth + 10;
            if (MSNWidget.platformConnector.isDocked()) subcat.Opacity = 0;
            canv_subcats.children.add(subcat);
            if(!MSNWidget.platformConnector.isDocked()) subcat.addEventListener("MouseLeftButtonDown", News.getNewsSubcat);

            if (width_all > root.findName("Subcat_Scroll").Width) {
                root.findName("subcat_right_btn").Visibility = "Visible";
                root.findName("subcat_left_btn").Visibility = "Collapsed";
            }
        }
        root.findName("subcat" + cat).Foreground = "#fff";

        // Angedockter Zustand:
        // Nur die aktive Subkategorie sichtbar machen, und den Gesamten Canvas so verschieben, dass die aktive
        // Kategorie zentriert ist
        if (MSNWidget.platformConnector.isDocked()) {
            root.findName("subcat" + MSNWidget.newsCat).Opacity = 1;
            root.findName("SubCats")["Canvas.Left"] = (root.findName("subcat" + MSNWidget.newsCat)["Canvas.Left"] - (root.findName("Subcat_Scroll").Width - root.findName("subcat" + MSNWidget.newsCat).ActualWidth) / 2) * (-1);
            
            //Herausfinden, welche Pfeil-Buttons angezeigt werden sollen
            if (root.findName("subcat" + MSNWidget.newsCat).equals(canv_subcats.children.getItem(0))) {
                root.findName("subcat_left_btn").Visibility = "Collapsed";
                root.findName("subcat_right_btn").Visibility = "Visible";
            } else if (root.findName("subcat" + MSNWidget.newsCat).equals(canv_subcats.children.getItem(canv_subcats.children.count - 1))) {
            root.findName("subcat_left_btn").Visibility = "Visible";
            root.findName("subcat_right_btn").Visibility = "Collapsed";
            } else {
            root.findName("subcat_left_btn").Visibility = "Visible";
            root.findName("subcat_right_btn").Visibility = "Visible";
            }
    }
    
    //Falls das Gadget nicht gedockt ist und eine Hauptkategorie aufgerufen wurde die Animation starten
    if(!MSNWidget.platformConnector.isDocked() && (MSNWidget.newsCat % 100) == 0) root.findName("Subcats_In").begin();
  }
  
GUI.zoomImage = function(image, start, stop, duration){
    var anim_str = '<Storyboard Name="img'+image.Name+'_zoom">';
    anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="'+image.Name+'" Storyboard.TargetProperty="Width">';
    anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="'+start+'"/>';
    anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="'+(stop+5)+'"/>';
    anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="'+stop+'"/>';
    anim_str += '</DoubleAnimationUsingKeyFrames>';
}

///////////////////////////////////////////////////////////////////////////////
//
//  installcreatesilverlight.js   			version 1.0
//
//  This file is provided by Microsoft as a helper file for websites that
//  incorporate Silverlight Objects. This file is provided under the Silverlight 
//  SDK 1.0 license available at http://go.microsoft.com/fwlink/?linkid=94240.  
//  You may not use or distribute this file or the code in this file except as 
//  expressly permitted under that license.
// 
//  Copyright (c) 2007 Microsoft Corporation. All rights reserved.
//
///////////////////////////////////////////////////////////////////////////////
if(!window.Silverlight)
    window.Silverlight={};


Silverlight.InstallAndCreateSilverlight = function(version, SilverlightDiv, installExperienceHTML, installPromptDivID, createSilverlightDelegate)
{
    var RetryTimeout=3000;	              //The interval at which Silverlight instantiation is attempted(ms)	
    if ( Silverlight.isInstalled(version) )
    {
	createSilverlightDelegate();
    }
    else
    {
	if ( installExperienceHTML && SilverlightDiv )
	{
	    SilverlightDiv.innerHTML=installExperienceHTML;
	    document.body.innerHTML;
	}
        if (installPromptDivID)
        {
	    var installPromptDiv = document.getElementById(installPromptDivID);
	    if ( installPromptDiv )
		installPromptDiv.innerHTML = Silverlight.createObject(null, null, null, {version: version, inplaceInstallPrompt:true},{}, null);
        }
	if ( ! (Silverlight.available || Silverlight.ua.Browser != 'MSIE' ) )
	{
	    TimeoutDelegate = function()
	    {
	        Silverlight.InstallAndCreateSilverlight(version, null, null, null, createSilverlightDelegate);
	    }
	    setTimeout(TimeoutDelegate, RetryTimeout);
	}
    }
}
var News = {};
News.isVideo = false;

//Set the color from the old subcat to inactive, fetch news and make the new
//subcat active
News.getNewsSubcat = function(sender, eventArgs) {
  sender.findName("subcat" + MSNWidget.newsCat).Foreground = "#CCC";
  News.getNews(parseInt(sender.name.substr(6)));
  sender.findName("subcat" + MSNWidget.newsCat).Foreground = "#FFF";
}

//Returns the name of the currently active category
News.getCategory = function(){
    var cat_act = Math.floor(MSNWidget.newsCat / 100) * 100;
    if(arguments.length == 1)
        cat_act = arguments[0];

    for(var i = 0; i < MSNWidget.categories.length; i++){
        if(MSNWidget.categories[i][2] == cat_act){
            return MSNWidget.categories[i][0];
            }
    }
}

//Returns the index of the currently active category
News.getCategoryIndex = function(){
    var cat_act = Math.floor(MSNWidget.newsCat / 100) * 100;

    var i = 0;
    for(; i < MSNWidget.categories.length; i++){
        if(MSNWidget.categories[i][2] == cat_act){
            return i;
        }
    }
}

//Returns the internal category-Code of a given Category-Index
News.getCategoryCode = function(index){
    return MSNWidget.categories[index][2];
}

//Funktion zum Abrufen eines Feeds und einfgen der Eintrge in XAML
News.getNews = function(category) {
    
    //Set all news to invisible
    MSNWidget.root.findName("NewsItems").Visibility = "Collapsed";
    
    var s = MSNWidget.root;
    GUI.Content.Events.locked = true;
    if(GUI.Content.Events.Interval != null) {
        window.clearTimeout(GUI.Content.Events.Interval);
        GUI.Content.Events.Interval = null;
    }
    MSNWidget.newsCat = category;
    
    MSNWidget.news = 0;
    MSNWidget.downloaded_images = 0;
    MSNWidget.platformConnector.saveSettings("SettingsPresent", true);
    MSNWidget.platformConnector.saveSettings("newsCat", category);
    
    //Kategorieüberschrift 
    s.findName("subcat_text").Text = News.getCategory();
         
    News.clearNews();
  
    //Ladebalken initialisieren
    s.findName("Loading_Bar").Width = 0;
    s.findName("Loading_Bar_refl").Width = 0;
    s.findName("LoadingIn").begin();
    
    var maincat = Math.floor(MSNWidget.newsCat / 100) - 1;
    var subcat = MSNWidget.newsCat % 100;
    
    News.isVideo = locale.subcats[maincat][subcat][2];
    var url = locale.subcats[maincat][subcat][1];
  
  News.getRSS(url, s);

}

News.getRSS = function(url, s) {
    MSNWidget.platformConnector.getData(url);
}

News.showError = function(code, sender){
var s = MSNWidget.root;
var counter = s.findName("NewsItems").Children.Count;
var err_obj = '<TextBlock Name="ErrorMsg'+counter+'" Canvas.Left="0" Canvas.Top="50" Text="" FontSize="9" Foreground="#FFDDDDFF" TextWrapping="Wrap" />';
var err_xaml = s.getHost().content.createFromXaml(err_obj);
err_xaml.Width = s.findName("NewsItemsContainer").Width - 10;

s.findName("NewsItems").children.add(err_xaml);


switch(code){
    case 0: s.findName("ErrorMsg"+counter).Text = locale.news.error0;break;
    case 12007: s.findName("ErrorMsg"+counter).Text = locale.news.error12007;break;
    case 12029: s.findName("ErrorMsg"+counter).Text = locale.news.error12029;break;

    default: s.findName("ErrorMsg"+counter).Text = locale.news.errorDefault;break;
}

    //Align horizontally
    err_xaml["Canvas.Left"] = (s.findName("NewsItemsContainer").Width - err_xaml.ActualWidth )/2;

    s.findName("LoadingOut").begin();
    
    GUI.Content.Events.fadeNewsIn();
    GUI.update();
    GUI.Content.Events.locked = false;
    return;
}

News.showError2 = function(text){
    News.clearNews();
    var s = MSNWidget.root;
    var counter = s.findName("NewsItems").Children.Count;
    var err_obj = '<TextBlock Name="ErrorMsg'+counter+'" Canvas.Left="10" Canvas.Top="'+(30*(counter+1))+'" Width="300" Text="" FontSize="9" Foreground="#FFDDDDFF" TextWrapping="Wrap" />';
    var err_xaml = s.getHost().content.createFromXaml(err_obj);


    s.findName("NewsItems").children.add(err_xaml);


    s.findName("ErrorMsg"+counter).Text = text;

    s.findName("LoadingOut").begin();
    
    GUI.Content.Events.fadeNewsIn();
    GUI.update();
    GUI.Content.Events.locked = false;
    return;
}

//Funktion zum Einfgen der einzelnen Eintrge in das Dokument
News.processData = function(response) {
    
    var s = MSNWidget.root;

    MSNWidget.preview.splice(0, MSNWidget.preview.length);
    MSNWidget.preview_img.splice(0, MSNWidget.preview_img.length);
    MSNWidget.preview_date.splice(0, MSNWidget.preview_date.length);
    MSNWidget.preview_title.splice(0, MSNWidget.preview_title.length);
    MSNWidget.preview_link.splice(0, MSNWidget.preview_link.length);
    
    

    if (response == null || typeof (response) != "object" ||
                      response.firstChild == null || response.getElementsByTagName("item").length == 0) {

        News.showError(0);
        return;
    }

    var entry;
    var entries = response.getElementsByTagName("item");
    var counter = -1;
    
    News.clearNews();
    for(var r = 0; r < entries.length; r++) {
        entry = entries.item(r);

        var desc_val = "";
        if(entry.getElementsByTagName("title").item(0).firstChild == null) {
          continue;
        }

        counter++;
        
        var title_val = entry.getElementsByTagName("title").item(0).firstChild.nodeValue;

        if (entry.getElementsByTagName("description").length != 0 && entry.getElementsByTagName("description").item(0).firstChild != null) {
            desc_val = News.deleteTags(entry.getElementsByTagName("description").item(0).firstChild.nodeValue);
        }

        //Sonderzeichen maskieren
        var re = /&/g;
        title_val = title_val.replace(re, "&amp;");
        desc_val = desc_val.replace(re, "&amp;");

        re = /\"/g;
        title_val = title_val.replace(re, "'");
        desc_val = desc_val.replace(re, "'");
        
        if(desc_val.length == 0)
            desc_val = locale.news_no_description;
        
        MSNWidget.preview.push(desc_val);
        MSNWidget.preview_title.push(title_val);
        
        if(desc_val == "")desc_val = locale.news_no_description;
        
        if(entry.getElementsByTagName("pubDate").length != 0){
            var date = Date.parse(entry.getElementsByTagName("pubDate").item(0).firstChild.nodeValue);
            if(isNaN(date))
                date = 0;
            else {
                date = new Date(date);
                MSNWidget.preview_date.push(date.getTime());
            }
        } else {
            MSNWidget.preview_date.push(0);
        }
        
        re = /&/g;
        var link_val = entry.getElementsByTagName("link").item(0).firstChild.nodeValue;
        link_val = link_val.replace(re, "&amp;");
        MSNWidget.preview_link.push(link_val);   
        
        //Beim ersten Eintrag unter umstnden Bild laden
        var link = "";
        if (entry.getElementsByTagName("enclosure").length != 0) {
            link = entry.getElementsByTagName("enclosure").item(0).getAttribute("url");
            
            //Check if the image has the right format or else switch to a default- image
            var ending = link.substring(link.length - 3);
            if(ending != "jpg" && ending != "png")
                link = config.image_str + "default/"+News.getCategory()+".jpg";
                
        } else link = config.image_str + "default/"+News.getCategory()+".jpg";
        MSNWidget.preview_img.push(link);
              
    }
    MSNWidget.total_images = counter+1;
    
    //Sort the news and the corresponding data
//    News.multisort(new Array(MSNWidget.preview_date, 
//                            MSNWidget.preview,
//                            MSNWidget.preview_img,
//                            MSNWidget.preview_title,
//                            MSNWidget.preview_link));
//                                 
    if(News.isVideo && !MSNWidget.platformConnector.isDocked()){
        News.populateSilverlightVideo();
    }
    else {
        News.populateSilverlightNews();
    }
     
    //Download and add the images   
    for(var i = 0; i < MSNWidget.preview_img.length; i++) {                   
        if(!MSNWidget.platformConnector.isDocked()){
            if(News.isVideo)
                News.makeVideoBarImage(i, MSNWidget.preview_img[i]);
            else 
                News.makeImage(i, MSNWidget.preview_img[i]);
        } else {
            GUI.Content.Events.downloader(null, i);
        }  
    }
}

News.populateSilverlightNews = function(){

    var s = MSNWidget.root;
    var rssCon = s.findName("NewsItems");
    rssCon.Opacity = 0;
    var rect_width = Math.round(MSNWidget.root.findName("NewsItems").Width - 10 );
    var canv_top = (MSNWidget.platformConnector.isDocked()) ? config.news.top_docked : config.news.top_undocked;
    var step = (MSNWidget.platformConnector.isDocked()) ? config.news.height_docked : config.news.height;
    var numNews = (MSNWidget.platformConnector.isDocked()) ? config.news.limit_docked : config.news.limit_undocked;
    numNews = (numNews > MSNWidget.preview_title.length) ? MSNWidget.preview_title.length : numNews;
    
    for(var i = 0 ; i < numNews; i++){

        //XAML-String erstellen
        var news_story_str = '<Canvas Name="News'+i+'" Canvas.Top="' + canv_top + '" Width="'+rect_width+'" Height="'+step+'" >';
        news_story_str += '<Rectangle Visibility="Visible" Opacity="0" Name="News_canvas'+i+'_Hover" Width="'+rect_width+'" Height="'+step+'" >';
        news_story_str += '<Rectangle.Fill>';
        news_story_str += '<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1" >';
        news_story_str += '<GradientStop Color="#6DDD" Offset="0.09" />';
        news_story_str += '<GradientStop Color="#4DDD" Offset="0.13" />';
        news_story_str += '<GradientStop Color="#3AAA" Offset="0.48" />';
        news_story_str += '<GradientStop Color="#4AAA" Offset="0.49" />';
        news_story_str += '<GradientStop Color="#5AAA" Offset="0.51" />';
        news_story_str += '<GradientStop Color="#2AAA" Offset="0.52" />';
        news_story_str += '<GradientStop Color="#3DDD" Offset="0.87" />';
        news_story_str += '<GradientStop Color="#5DDD" Offset="0.91" />';
        news_story_str += '</LinearGradientBrush>';
        news_story_str += '</Rectangle.Fill>';
        news_story_str += '</Rectangle>';
        news_story_str += '<TextBlock Name="Text' + i + '" Canvas.Left="5" Text="' + MSNWidget.preview_title[i] + '" TextWrapping="NoWrap" Foreground="'+config.news.hl_color+'"';
        news_story_str += (MSNWidget.platformConnector.isDocked()) ? ' FontSize="8.5"' : ' FontSize="9"';
        news_story_str += ' Cursor="Hand" />';
        news_story_str += '</Canvas>';

        var previewLeft = 0;
        var previewWidth = document.getElementById("MSNSilverlight").offsetWidth - s.findName("NewsItems")["Canvas.Left"] - 15;

        var news_story_preview = '<Canvas Canvas.ZIndex="2" Canvas.Left="' + previewLeft + '" Name="Preview' + i + '" Visibility="Collapsed" Opacity="0" >';
        news_story_preview += '<Rectangle Width="' + previewWidth + '" Name="Preview'+i+'_bg" Stroke="#FFaaaaaa" StrokeThickness="0.5" RadiusX="1" RadiusY="1" Opacity="1">';
        news_story_preview += '<Rectangle.Fill>';
        news_story_preview += '<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1" >';
        news_story_preview += '<GradientStop Color="#FF000000" Offset="0"/>';
        news_story_preview += '<GradientStop Color="#FF222222" Offset="0.8"/>';
        news_story_preview += '<GradientStop Color="#FF000000" Offset="1"/>';
        news_story_preview += '</LinearGradientBrush>';
        news_story_preview += '</Rectangle.Fill>';
        news_story_preview += '</Rectangle>';
        news_story_preview += '<TextBlock Canvas.Top="6" Canvas.Left="6" Width="' + (previewWidth-12) + '" Name="PreviewTextText' + i + '" Text="' + MSNWidget.preview[i] + '" TextWrapping="Wrap" ';
        news_story_preview += 'FontSize="11" Foreground="#FFBBBBBB" FontWeight="Thin" FontFamily="Trebuchet MS" Cursor="Hand" />';
        news_story_preview += '<Rectangle Name="PreviewLinkText_bg'+i+'" Canvas.Left="4" Width="70" Height="16" RadiusX="4" RadiusY="4" Stroke="#ffd46d04" StrokeThickness="0.5">';
        news_story_preview += '<Rectangle.Fill>';
        news_story_preview += '<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1" >';
        news_story_preview += '<GradientStop Color="#FFfef3df" Offset="0"/>';
        news_story_preview += '<GradientStop Color="#FFfca031" Offset="0.5"/>';
        news_story_preview += '<GradientStop Color="#FFef7806" Offset="1"/>';
        news_story_preview += '</LinearGradientBrush>';
        news_story_preview += '</Rectangle.Fill>';
        news_story_preview += '</Rectangle>';
        news_story_preview += '<TextBlock Canvas.Left="8" Width="' + (previewWidth-12) + '" Name="PreviewLinkText' + i + '" Text="'+locale.news.readmore+'" TextWrapping="Wrap" ';
        news_story_preview += 'FontFamily="Trebuchet MS" Foreground="#f000" FontSize="11" Cursor="Hand" /> ';
        news_story_preview += '<Path Canvas.Top="4" Canvas.Left="7" Stretch="Fill" Fill="#000" StrokeThickness="5" Data="M6,5 L1,10 1,1 z" Name="PreviewLinkPath'+i+'" />';
        news_story_preview += '<Canvas Name="PreviewCloseText'+i+'" Canvas.Top="2" Width="10" Height="10" Cursor="Hand" >';
        news_story_preview += '<Line X1="2" Y1="2" X2="8" Y2="8" Stroke="#ddd" StrokeThickness="0.5" Cursor="Hand" />';
        news_story_preview += '<Line X1="2" Y1="8" X2="8" Y2="2" Stroke="#ddd" StrokeThickness="0.5" Cursor="Hand" />';
        news_story_preview += '<Rectangle Height="10" Width="10" RadiusX="1" Fill="#03000000" RadiusY="1" Stroke="#ddd" Cursor="Hand" StrokeThickness="0.5" />';
        news_story_preview += '</Canvas>';
        
        news_story_preview += '<TextBlock Name="Link' + i + '" Text="' + MSNWidget.preview_link[i] + '" Visibility="Collapsed" />';
        news_story_preview += '</Canvas>';

        canv_top += step;
        
        //The line between the news-headlines
        var line_str = '<Line Canvas.Top="'+canv_top+'" Name="Line'+i+'" X1="0" Y1="0" X2="'+rect_width+'" Y2="0" Stroke="#FAAA" StrokeThickness="0.8" />';

        //XAML anhngen
        var control = s.getHost();
        var storyTags = control.content.createFromXaml(news_story_str);
        var storyPreview = control.content.createFromXaml(news_story_preview);
        var line = control.content.createFromXaml(line_str);
        storyTags.findName("Text"+i).Text = News.trim(storyTags.findName("Text"+i), rect_width - 5);
        
        //Align the text vertically
        storyTags.findName("Text" + i)["Canvas.Top"] = step / 2 - storyTags.findName('Text' + i).ActualHeight / 2;
        
        //Trim the preview-text on the right lenght
        while(storyPreview.findName("PreviewTextText"+i).ActualHeight > 80){
            storyPreview.findName("PreviewTextText"+i).Text = storyPreview.findName("PreviewTextText"+i).Text.substring(0, storyPreview.findName("PreviewTextText"+i).Text.length - 5) + "...";
        } 
        
        rssCon.children.add(storyTags);
        rssCon.children.add(storyPreview);
        if(i < numNews -1)
            rssCon.children.add(line);
        storyTags.findName("News" + i).addEventListener("MouseEnter", GUI.Content.Events.handleMouseIn_News);
        storyTags.findName("News" + i).addEventListener("MouseLeave", GUI.Content.Events.handleMouseOut_News);
        storyTags.findName("News" + i).addEventListener("MouseLeftButtonDown", GUI.Content.Events.handleMouseFeedDown);
        s.findName("PreviewLinkText"+i).addEventListener("MouseLeftButtonDown", GUI.Content.Events.handleMouseMoreDown);
        s.findName("PreviewTextText"+i).addEventListener("MouseLeftButtonDown", GUI.Content.Events.handleMouseMoreDown);
        s.findName("PreviewCloseText"+i).addEventListener("MouseLeftButtonDown", GUI.preview.closePreview);
        s.findName("Preview" + i+"_bg")["Height"] = 110;
        s.findName("PreviewLinkText"+i)["Canvas.Top"] = s.findName("PreviewTextText"+i).ActualHeight + s.findName("PreviewTextText" + i)["Canvas.Top"] + 6;
        s.findName("PreviewLinkText_bg"+i)["Canvas.Top"] = s.findName("PreviewTextText"+i).ActualHeight + s.findName("PreviewTextText" + i)["Canvas.Top"]  + 4;
        s.findName("PreviewLinkPath"+i)["Canvas.Top"] = s.findName("PreviewLinkText_bg"+i)["Canvas.Top"] + 4;
        s.findName("PreviewLinkText_bg" +i).Width = s.findName("PreviewLinkText"+i).ActualWidth + 25;
        s.findName("PreviewLinkText_bg"+i)["Canvas.Left"] = (s.findName("Preview" + i+"_bg").Width / 2) - (s.findName("PreviewLinkText_bg"+i).Width / 2);
        s.findName("PreviewLinkText"+i)["Canvas.Left"] = s.findName("PreviewLinkText_bg"+i)["Canvas.Left"] + 20;
        s.findName("PreviewLinkPath"+i)["Canvas.Left"] = s.findName("PreviewLinkText_bg"+i)["Canvas.Left"] + 6;
        s.findName("PreviewCloseText"+i)["Canvas.Left"] = s.findName("Preview"+i+"_bg").Width - 12;
  
    }
    GUI.update();
}

//If it's a news-category build the corresponing XAML
News.populateSilverlightVideo = function() {
    
    var s = MSNWidget.root;
    var entry;
    var canv_top = 20;
    var left = -(s.findName("NewsItems")["Canvas.Left"] - 5);

    s.findName("NewsItems").Opacity = "0";
    s.findName("NewsItems")["Canvas.Left"] = 4;
        
    //XAML-String erstellen
    var video_title_str = '<Canvas Canvas.Left="'+left+'"><TextBlock Name="VideoTitle" Canvas.Top="25" Canvas.Left="114" Text="' + MSNWidget.preview_title[0] + '" TextWrapping="Wrap" FontSize="11" LineHeight="12.0" LineStackingStrategy="BlockLineHeight" Foreground="#FFDDDDDD" /></Canvas>';
    
    var video_desc_str = '<TextBlock Canvas.Top="40" Canvas.Left="'+(left + 114)+'" Name="VideoDesc" Text="' + MSNWidget.preview[0] + '" TextWrapping="Wrap" FontSize="9" LineHeight="10.0" LineStackingStrategy="BlockLineHeight" Foreground="#FFDDDDDD" Cursor="Arrow" />';
    
    var video_bar_str = '<Canvas Name="VideoBarContainer" Canvas.Top="140" Canvas.Left="'+left+'">';
    
    video_bar_str += '<Rectangle Canvas.Left="6" Name="left_btn_bg" Width="18" Height="40" RadiusX="4" RadiusY="4" Canvas.ZIndex="3">';
    video_bar_str += '<Rectangle.Fill>';
    video_bar_str += '<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" >';
    video_bar_str += '<GradientStop Color="#FF444444" Offset="0"/>';
    video_bar_str += '<GradientStop Color="#FF222222" Offset="0.496"/>';
    video_bar_str += '<GradientStop Color="#FF000000" Offset="0.522"/>';
    video_bar_str += '<GradientStop Color="#FF333333" Offset="1"/>';
    video_bar_str += '</LinearGradientBrush>';
    video_bar_str += '</Rectangle.Fill>';
    video_bar_str += '</Rectangle>';
    
    video_bar_str += '<Path Canvas.Top="4" Canvas.Left="7" Stretch="Fill" StrokeThickness="5" Data="M1,19 L15,4 15,36 z" Name="video_left_btn" Opacity="1" Canvas.ZIndex="4">';
    video_bar_str += '<Path.Fill>';
    video_bar_str += '<LinearGradientBrush EndPoint="0.4,1" StartPoint="0.6,0" >';
    video_bar_str += '<GradientStop Color="#FFDDDDDD" Offset="0"/>';
    video_bar_str += '<GradientStop Color="#FF909090" Offset="0.496"/>';
    video_bar_str += '<GradientStop Color="#FF444444" Offset="0.522"/>';
    video_bar_str += '<GradientStop Color="#FF666666" Offset="1"/>';
    video_bar_str += '</LinearGradientBrush>';
    video_bar_str += '</Path.Fill>';
    video_bar_str += '</Path>';
    
    video_bar_str += '<Rectangle Name="right_btn_bg" Width="18" Height="40" RadiusX="4" RadiusY="4" Canvas.ZIndex="3">';
    video_bar_str += '<Rectangle.Fill>';
    video_bar_str += '<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" >';
    video_bar_str += '<GradientStop Color="#FF444444" Offset="0"/>';
    video_bar_str += '<GradientStop Color="#FF222222" Offset="0.496"/>';
    video_bar_str += '<GradientStop Color="#FF000000" Offset="0.522"/>';
    video_bar_str += '<GradientStop Color="#FF333333" Offset="1"/>';
    video_bar_str += '</LinearGradientBrush>';
    video_bar_str += '</Rectangle.Fill>';
    video_bar_str += '</Rectangle>';
    
    video_bar_str += '<Path Canvas.Top="4" Stretch="Fill" StrokeThickness="5" Data="M1,19 L15,4 15,36 z" Name="video_right_btn" RenderTransformOrigin="0.5,0.5" Canvas.Left="206.809" Opacity="1" Canvas.ZIndex="4">';
    video_bar_str += '<Path.Fill>';
    video_bar_str += '<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" >';
    video_bar_str += '<GradientStop Color="#FFDDDDDD" Offset="0"/>';
    video_bar_str += '<GradientStop Color="#FF909090" Offset="0.496"/>';
    video_bar_str += '<GradientStop Color="#FF444444" Offset="0.522"/>';
    video_bar_str += '<GradientStop Color="#FF666666" Offset="1"/>';
    video_bar_str += '</LinearGradientBrush>';
    video_bar_str += '</Path.Fill>';
    video_bar_str += '<Path.RenderTransform>';
    video_bar_str += '<TransformGroup>';
    video_bar_str += '<ScaleTransform ScaleX="-1" ScaleY="1"/>';
    video_bar_str += '</TransformGroup>';
    video_bar_str += '</Path.RenderTransform>';
    video_bar_str += '</Path>';
    
    video_bar_str += '<Canvas Name="VideoBar" Canvas.Left="20" Canvas.ZIndex="2">';
    video_bar_str += '</Canvas>';
    
    video_bar_str += '<Rectangle Name="VideoBar_bg">';
    video_bar_str += '<Rectangle.Fill>';
    video_bar_str += '<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" >';
    video_bar_str += '<GradientStop Color="#FFDDDDDD" Offset="0"/>';
    video_bar_str += '<GradientStop Color="#FF909090" Offset="0.496"/>';
    video_bar_str += '<GradientStop Color="#FF444444" Offset="0.522"/>';
    video_bar_str += '<GradientStop Color="#FF666666" Offset="1"/>';
    video_bar_str += '</LinearGradientBrush>';
    video_bar_str += '</Rectangle.Fill>';
    video_bar_str += '</Rectangle>';
    video_bar_str += '</Canvas>';

    //XAML anhngen
    var control = s.getHost();
    var videoTitle = control.content.createFromXaml(video_title_str);
    var videoDesc = control.content.createFromXaml(video_desc_str);
    var videoBar = control.content.createFromXaml(video_bar_str);
    
    //Ueberprfen, ob die einzelnen Items noch in die Anzeige passen,
    //falls nicht ScrollBar anzeigen
    var rssCon = s.findName("NewsItems");
    videoBar.findName("video_right_btn")["Canvas.Left"] = rssCon.findName("NewsItems_Bg").Width - videoBar.findName("video_right_btn").Width - 2;
    videoBar.findName("right_btn_bg")["Canvas.Left"] = rssCon.findName("NewsItems_Bg").Width - videoBar.findName("right_btn_bg").Width - 2;
    
    videoTitle.findName("VideoTitle").Width = rssCon.findName("NewsItems_Bg").Width - 120;
    videoDesc.Width = rssCon.findName("NewsItems_Bg").Width - 120;
    videoDesc["Canvas.Top"] = videoTitle.findName("VideoTitle").ActualHeight + videoTitle.findName("VideoTitle")["Canvas.Top"] + 5;
    
    rssCon.children.add(videoTitle);
    rssCon.children.add(videoDesc);
    rssCon.children.add(videoBar);
    
    rssCon.findName("video_right_btn").addEventListener("MouseLeftButtonDown", GUI.Video.switchVideo);
    rssCon.findName("video_left_btn").addEventListener("MouseLeftButtonDown", GUI.Video.switchVideo);
    
    GUI.update();
}

News.makeVideoBarImage = function(counter, link){
    var str = '<Canvas Canvas.Top="'+config.video.small_top+'" Canvas.Left="'+(counter*55)+'" Name="preview_'+counter+'" Canvas.ZIndex="'+counter+'">';
    str += '<Image Name="preview_img_'+counter+'" Width="40" Cursor="Hand" Source="" />';
    str += '<Image Name="preview_img_play_'+counter+'" Width="40" Cursor="Hand" Source="'+config.image_str + 'play.png" Opacity="0" Visibility="Collapsed" />';
    str += '<Image Name="preview_img_refl_'+counter+'" Width="40" Source="" Canvas.Top="50" >';
    str += '<Image.RenderTransform>';
    str += '<ScaleTransform ScaleY="-1" />';
    str += '</Image.RenderTransform>';
    str += '<Image.OpacityMask>';
    str += '<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">';
    str += '<GradientStop Color="#00000000" Offset="0.0" />';
    str += '<GradientStop Color="#44FFFFFF" Offset="1.0" />';
    str += '</LinearGradientBrush>';
    str += '</Image.OpacityMask>';
    str += '</Image></Canvas>';
    
    var imgTags = MSNWidget.root.getHost().content.createFromXaml(str);
    imgTags.findName("preview_img_"+counter).addEventListener("MouseEnter", GUI.Content.Events.video_in);
    imgTags.findName("preview_img_"+counter).addEventListener("MouseLeave", GUI.Content.Events.video_out);
    imgTags.findName("preview_img_"+counter).addEventListener("MouseLeftButtonDown", GUI.Content.Events.video_prsd);
    imgTags.findName("preview_img_play_"+counter).addEventListener("MouseLeftButtonDown", GUI.Content.Events.video_prsd);
    MSNWidget.root.findName("VideoBar").children.add(imgTags);
    
    //Falls nicht vorhanden, die Animationen erstellen
    if(MSNWidget.root.findName("VideoImgOut"+counter) == null){
        var anim_str = '<Storyboard Name="VideoImgOut'+counter+'" >';
   
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Left)" Storyboard.TargetName="preview_'+counter+'">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="-15"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="preview_img_play_'+counter+'" Completed="hideSelf">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.7"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '</Storyboard>';
        var anim_obj = MSNWidget.root.getHost().content.createFromXaml(anim_str);
        MSNWidget.root.findName('preview_'+counter).Resources.add(anim_obj);
        
        
        anim_str = '<Storyboard Name="VideoImgOut_Scale'+counter+'">';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="preview_img_'+counter+'" Storyboard.TargetProperty="Width">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="100"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="40"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="preview_img_'+counter+'" Storyboard.TargetProperty="(Canvas.Top)">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="-105"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="preview_img_play_'+counter+'" Storyboard.TargetProperty="Width">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="100"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="40"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="preview_img_play_'+counter+'" Storyboard.TargetProperty="(Canvas.Top)">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="-105"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="preview_img_refl_'+counter+'" Storyboard.TargetProperty="Width">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="100"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="40"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="preview_img_refl_'+counter+'" Storyboard.TargetProperty="(Canvas.Top)">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="52"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '</Storyboard>';
        anim_obj = MSNWidget.root.getHost().content.createFromXaml(anim_str);
        MSNWidget.root.findName('preview_'+counter).Resources.add(anim_obj);
        
        anim_str = '<Storyboard Name="VideoImgIn'+counter+'" >';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Left)" Storyboard.TargetName="preview_'+counter+'">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="-15"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="preview_img_play_'+counter+'">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0.7"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>'; 
        anim_str += '</Storyboard>';
        anim_obj = MSNWidget.root.getHost().content.createFromXaml(anim_str);
        MSNWidget.root.findName('preview_'+counter).Resources.add(anim_obj);
        
        
        anim_str = '<Storyboard Name="VideoImgIn_Scale'+counter+'">';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="preview_img_'+counter+'" Storyboard.TargetProperty="Width">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="40"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="100"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="preview_img_'+counter+'" Storyboard.TargetProperty="(Canvas.Top)">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="-105"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="preview_img_play_'+counter+'" Storyboard.TargetProperty="Width">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="40"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="100"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="preview_img_play_'+counter+'" Storyboard.TargetProperty="(Canvas.Top)">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="-105"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="preview_img_refl_'+counter+'" Storyboard.TargetProperty="Width">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="40"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="100"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="preview_img_refl_'+counter+'" Storyboard.TargetProperty="(Canvas.Top)">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="-50"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="-95"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>'; 
        anim_str += '</Storyboard>';
        anim_obj = MSNWidget.root.getHost().content.createFromXaml(anim_str);
        MSNWidget.root.findName('preview_'+counter).Resources.add(anim_obj);
    }
    
    //Falls ein Standartbild angezeigt wird
    if(link.substring(0, config.image_str.length) == config.image_str){
        MSNWidget.root.findName("preview_img_"+counter).Source = link;
        MSNWidget.root.findName("preview_img_refl_"+counter).Source = link;
        GUI.Content.Events.downloader_video(null, counter);
    }else {
        // Retrieve a reference to the plug-in.
        var slPlugin = MSNWidget.root.getHost();

        // Create a Downloader object.
        var downloader = slPlugin.createObject("downloader");

        downloader.addEventListener("completed", function(sender){GUI.Content.Events.downloader_video(sender, counter)});
        downloader.open("GET", link);
        downloader.send();
    }
}

//Creates the XAML for a news-image and starts the download of it
News.makeImage = function(counter, link) {
    var img_str = '<Canvas Name="canvas_news_img_'+counter+'" Canvas.Left="-220" Canvas.ZIndex="'+counter+'"><Image Name="news_img_'+counter+'" Canvas.ZIndex="2" Cursor="Hand" Canvas.Left="2" Canvas.Top="2" Source="';
    img_str += '" />';
    img_str += '<Image Canvas.ZIndex="2" Name="news_img_refl_'+counter+'" Source="" Canvas.Left="2" >';
    img_str += '<Image.RenderTransform>';
    img_str += '<ScaleTransform ScaleY="-1" />';
    img_str += '</Image.RenderTransform>';
    img_str += '<Image.OpacityMask>';
    img_str += '<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">';
    img_str += '<GradientStop Color="#00000000" Offset="0.0" />';
    img_str += '<GradientStop Color="#44FFFFFF" Offset="1.0" />';
    img_str += '</LinearGradientBrush>';
    img_str += '</Image.OpacityMask>';
    img_str += '</Image></Canvas>';
    if (!MSNWidget.platformConnector.isDocked()) {
        var imgTags = MSNWidget.root.getHost().content.createFromXaml(img_str);
        
        if(MSNWidget.root.findName('canvas_news_img_'+counter) == null){
            MSNWidget.root.findName("NewsImage").children.add(imgTags);
        }
        //MSNWidget.root.findName("news_img_ld_"+counter).Source = config.image_str + "loadingImg.png";
        //MSNWidget.root.findName("news_img_refl_ld_"+counter).Source = config.image_str + "loadingImg.png";
        MSNWidget.root.findName('news_img_'+counter).addEventListener("MouseLeftButtonDown", GUI.Content.Events.handleMouseFeedDown);
        MSNWidget.root.findName('news_img_'+counter).addEventListener("ImageFailed", function(){});
        MSNWidget.root.findName('news_img_refl_'+counter).addEventListener("ImageFailed", function(){});
        
        //GUI.update();
    }
    
    //Falls nicht vorhanden, die Animationen erstellen
    if(MSNWidget.root.findName("NewsImgOut"+counter) == null){
        var anim_str = '<Storyboard Name="NewsImgOut'+counter+'" >';
        
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Left)" Storyboard.TargetName="canvas_news_img_'+counter+'">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="2"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="130"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '</Storyboard>';
        var anim_obj = MSNWidget.root.getHost().content.createFromXaml(anim_str);
        MSNWidget.root.findName('canvas_news_img_'+counter).Resources.add(anim_obj);
        
        
        anim_str = '<Storyboard Name="NewsImgOut_Scale'+counter+'" Completed="restore_img">';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="news_img_'+counter+'" Storyboard.TargetProperty="Width">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="100"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="1"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="news_img_'+counter+'" Storyboard.TargetProperty="(Canvas.Top)">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="40"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="news_img_refl_'+counter+'" Storyboard.TargetProperty="Width">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="100"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="1"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="news_img_refl_'+counter+'" Storyboard.TargetProperty="(Canvas.Top)">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="40"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '</Storyboard>';
        anim_obj = MSNWidget.root.getHost().content.createFromXaml(anim_str);
        MSNWidget.root.findName('canvas_news_img_'+counter).Resources.add(anim_obj);
        
        anim_str = '<Storyboard Name="NewsImgIn'+counter+'" >';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Left)" Storyboard.TargetName="canvas_news_img_'+counter+'">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="-200"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="2"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '</Storyboard>';
        anim_obj = MSNWidget.root.getHost().content.createFromXaml(anim_str);
        MSNWidget.root.findName('canvas_news_img_'+counter).Resources.add(anim_obj);
        
        
        anim_str = '<Storyboard Name="NewsImgIn_Scale'+counter+'">';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="news_img_'+counter+'" Storyboard.TargetProperty="Width">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="150"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="100"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="news_img_'+counter+'" Storyboard.TargetProperty="(Canvas.Top)">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="25"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="news_img_refl_'+counter+'" Storyboard.TargetProperty="Width">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="150"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="100"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="news_img_refl_'+counter+'" Storyboard.TargetProperty="(Canvas.Top)">';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>';
        anim_str += '<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="200"/>';
        anim_str += '</DoubleAnimationUsingKeyFrames>';
        anim_str += '</Storyboard>';
        anim_obj = MSNWidget.root.getHost().content.createFromXaml(anim_str);
        MSNWidget.root.findName('canvas_news_img_'+counter).Resources.add(anim_obj);
    }
    
    //Falls ein Standartbild angezeigt wird
    if(link.substring(0, config.image_str.length) == config.image_str){
        MSNWidget.root.findName("news_img_"+counter).Source = link;
        MSNWidget.root.findName("news_img_refl_"+counter).Source = link;
        GUI.Content.Events.downloader(null, counter);
    }else {
        // Create a Downloader object.
        MSNWidget.platformConnector.setImage(link, counter);
    }
}

News.deleteTags = function(txt) {
  var txt_strip = txt;
  while(txt_strip.indexOf('<') != -1) {
    var first = txt.indexOf('<');
    var last = txt.indexOf('>');
    txt_strip = txt.substr(0, first);
    txt_strip = txt_strip + txt.substr(last+1);
    txt = txt_strip;
    
  }
  return txt_strip;
}

//Alle momentanten Eintrge lschen
News.clearNews = function() {
    var root = MSNWidget.root;
    var canvas = root.findName("NewsItems");
    canvas["Canvas.Top"] = 0;
    canvas.Children.Clear();
    if(root.findName("canvas_news_img_0") != null) {
        root.findName("NewsImage").Children.Clear();
    }
}

//Die Eintrge auf die richtige Lnge krzen
News.trim = function(obj, width) {
  var root = MSNWidget.root;
  while(obj.ActualWidth > width) {
      obj.Text = obj.Text.substr(0, obj.Text.length - 4) + "...";
  }
  obj.Width = width;
  return obj.Text;
}

News.openCategory = function(){
    var category = News.getCategoryIndex();
        window.open(MSNWidget.categories[category][1]);
}

//Feglermeldung anzeigen
function xaml_error(sender, errorArgs)
{
    {
    // The error message to display.
    var errorMsg = "Silverlight Error: \n\n";
    
    // Error information common to all errors.
    errorMsg += "Error Type:    " + errorArgs.errorType + "\n";
    errorMsg += "Error Message: " + errorArgs.errorMessage + "\n";
    errorMsg += "Error Code:    " + errorArgs.errorCode + "\n";
    
    // Determine the type of error and add specific error information.
    switch(errorArgs.errorType)
    {
        case "RuntimeError":
            // Display properties specific to RuntimeErrorEventArgs.
            if (errorArgs.lineNumber != 0) {
              errorMsg += "Line: " + errorArgs.lineNumber + "\n";
              errorMsg += "Position: " +  errorArgs.charPosition + "\n";
            }
            errorMsg += "MethodName: " + errorArgs.methodName + "\n";
            break;
        case "ParserError":
            // Display properties specific to ParserErrorEventArgs.
            errorMsg += "Xaml File:      " + errorArgs.xamlFile      + "\n";
            errorMsg += "Xml Element:    " + errorArgs.xmlElement    + "\n";
            errorMsg += "Xml Attribute:  " + errorArgs.xmlAttribute  + "\n";
            errorMsg += "Line:           " + errorArgs.lineNumber    + "\n";
            errorMsg += "Position:       " + errorArgs.charPosition  + "\n";
            break;
        default:
            break;
    }
    // Display the error message.
    alert(errorMsg);
}

}

News.saveCategories = function(){
    var save_str = "";
    for(var i = 0; i < MSNWidget.categories.length; i++){
        for(var j = 0; j < locale.categories.length; j++){
            if(MSNWidget.categories[i][0] == locale.categories[j][0]){
                save_str += j + "-";
                break;
            }
        }
    }
    save_str = save_str.substring(0, save_str.length-1);
    MSNWidget.platformConnector.saveSettings("categories", save_str);
    MSNWidget.platformConnector.saveSettings("SettingsPresent", true);
    
   
}

//Sorts the News from newest to oldest
News.multisort = function(arrayOfArrays){
    if(!arrayOfArrays || typeof(arrayOfArrays)!="object"){return false;};
    var gather=[];
    
    //Sort leading array only.
    arrayOfArrays[0].sort(
	    function(a,b){
	    var copyA=a+"";
	    var copyB=b+"";
	    return gather[++gather.length-1]=
	    (copyA.toLowerCase()<copyB.toLowerCase())?1:
	    (copyA.toLowerCase()>copyB.toLowerCase())?-1:0;
	    }
    );
    
    //Reorder other arrays:
    for(var i=1; i<arrayOfArrays.length; i++){
        var feedIterator=0;
        arrayOfArrays[i].sort(
	        function(a,b){
	        return gather[feedIterator++];
	        }
        );
    }
    return arrayOfArrays;
}


var dragdrop = {};
dragdrop.isdragging = false;
dragdrop.activated = false;
dragdrop.originX = 0;
dragdrop.originY = 0;
dragdrop.origin_more = false;
dragdrop.dragObj = null;
dragdrop.index_in = -1;
dragdrop.index_out = -1;

dragdrop.switchCats = function(category, index){

}

//Initialisation
dragdrop.start = function(sender, eventArgs){
    
    //Find out, which button is to be dragged
    for(var i = 0; i < MSNWidget.categories.length; i++){
        if(MSNWidget.categories[i][0] == dragdrop.dragObj.Name.substr(4)){
            dragdrop.index_out = i;
            break;
            }
    }
    
    //Find out, if its a button from the "more"-area or not
    var pos = eventArgs.getPosition(sender.findName("More_Container"));
    if(pos.x > 0 && pos.y > 0)dragdrop.origin_more = true;
    else dragdrop.origin_more = false;
    
    sender.findName("More")["Canvas.ZIndex"] = (dragdrop.origin_more) ? 11 : 9;
}

/** 
* Move the button along the mouse and adapt the bar accordingly
**/
dragdrop.moveBtn = function(sender, MouseEventArgs){

    var pos = MouseEventArgs.getPosition(null);
    var pos_more = MouseEventArgs.getPosition(sender.findName("More_Container"));
    
    //Falls die Maus über dem "More"-Knopf fährt, diesen Bereich anzeigen.
    var more_btn = sender.findName("Btn_More");
    if(pos.x <= (more_btn.Width + more_btn["Canvas.Left"]) && pos.x >= more_btn["Canvas.Left"]
        && pos.y <= (more_btn.Height + more_btn["Canvas.Top"]) && pos.y >= more_btn["Canvas.Top"]){
        sender.findName("More").Visibility = "Visible";
        if(sender.findName("More").Opacity == 0)
            sender.findName("More_In").Begin();
        }
    
    //Falls sich die Maus in der Kontrollzeile befindet
    if(pos.y < sender.findName("Buttons").Height){
        
        var btn_offset = sender.findName("Btn_MSN")["Canvas.Left"]+ sender.findName("Btn_MSN").Width;
        var btn_width = sender.findName("Btn_"+MSNWidget.categories[0][0]).Width + 2;
        
        dragdrop.index_in = Math.floor(Math.abs(pos.x - btn_offset) / btn_width );
        if(dragdrop.index_in > dragdrop.index_out)dragdrop.index_in++;
        dragdrop.rearrange(sender, MouseEventArgs, false);
        //Möglicherweise die "More"-Box erweitern
        if(!dragdrop.origin_more && dragdrop.index_in >= sender.findName("ButtonsCat").Children.Count){
            sender.findName("More").Height = (sender.findName("More_Container").Children.Count + 1) * 25;
            sender.findName("More_Bg2").Height = (sender.findName("More_Container").Children.Count + 1) * 25 + 10;
            sender.findName("More_Bg").Height = (sender.findName("More_Container").Children.Count + 1) * 25;
        } else {
            sender.findName("More").Height = (sender.findName("More_Container").Children.Count) * 25;
            sender.findName("More_Bg2").Height = (sender.findName("More_Container").Children.Count) * 25 + 10;
            sender.findName("More_Bg").Height = (sender.findName("More_Container").Children.Count) * 25
        }
    }
    //Ist die Maus im "More"-Bereich?
    else if(pos_more.x > 0 && pos_more.y > 0){
        var btn_height = sender.findName("More_Container").Children.GetItem(0).Height;
        dragdrop.index_in = Math.floor(Math.abs(pos_more.y) / btn_height ) + sender.findName("ButtonsCat").Children.Count;
        if(dragdrop.index_in > dragdrop.index_out)dragdrop.index_in++;
         //Möglicherweise die "More"-Box erweitern
        if(!dragdrop.origin_more && dragdrop.index_in >= sender.findName("ButtonsCat").Children.Count){
            sender.findName("More").Height = (sender.findName("More_Container").Children.Count + 1) * 25;
            sender.findName("More_Bg2").Height = (sender.findName("More_Container").Children.Count + 1) * 25 + 10;
            sender.findName("More_Bg").Height = (sender.findName("More_Container").Children.Count + 1) * 25;
        } else {
            sender.findName("More").Height = (sender.findName("More_Container").Children.Count) * 25;
            sender.findName("More_Bg2").Height = (sender.findName("More_Container").Children.Count) * 25 + 10;
            sender.findName("More_Bg").Height = (sender.findName("More_Container").Children.Count) * 25
        }
        dragdrop.rearrange(sender, MouseEventArgs, true);
    }
    
    //Button um den Mauszeiger zentrieren
    var position = (dragdrop.origin_more) ? pos_more : pos;
    dragdrop.dragObj["Canvas.Top"] = position.y - (dragdrop.dragObj.Height / 2);
    dragdrop.dragObj["Canvas.Left"] = position.x - (dragdrop.dragObj.Width / 2);
    dragdrop.dragObj["Canvas.ZIndex"] = 9;
    dragdrop.dragObj.Opacity = 0.7;
}

//Verschiebt die Knöpfen passend zur aktuellen Mausposition
dragdrop.rearrange = function(sender, MouseEventArgs, in_more){
    
    //Knöpfer der Kontrollzeile verschieben
    var btn_offset = sender.findName("Btn_MSN")["Canvas.Left"]+ sender.findName("Btn_MSN").Width;
    var btn_width = sender.findName("Btn_"+MSNWidget.categories[0][0]).Width + 2;

    var left = btn_offset;
    
    for(var i = 0; i < sender.findName("ButtonsCat").Children.Count; i++) {
        //Falls sich der Zeiger auf der Ursprünglichen Position des Knopfes befindet nur Platz lassen
        //und mit der nächste Iteration fortfahren
        if(dragdrop.index_out == dragdrop.index_in 
            && dragdrop.index_in == i){
            left += btn_width;                    
            continue;
        }else {
            //Falls es sich um den Knopf handelt, über dem der Zeiger steht Platz lassen
            if(dragdrop.index_in == i)left += btn_width;
            //Den Knopf, welcher gerade verschoben wird ignorieren
            if(dragdrop.index_out == i)continue;
            sender.findName("Btn_"+MSNWidget.categories[i][0])["Canvas.Left"] = left;
        }
       left += btn_width;
    }
    //Knöpfe des "More"-Bereichs verschieben
    var btn_height = sender.findName("More_Container").Children.GetItem(0).Height;

    var top = 5;
    
    for(var i = sender.findName("ButtonsCat").Children.Count; i < MSNWidget.categories.length; i++) {
        if(dragdrop.index_out == dragdrop.index_in 
            && dragdrop.index_in == i){
            top += btn_height;                    
            continue;
        }else {
            if(dragdrop.index_in == i)top += btn_height;
            if(dragdrop.index_out == i)continue;
            sender.findName("Btn_"+MSNWidget.categories[i][0])["Canvas.Top"] = top;
        }
       top += btn_height;
    }
}

//Wenn die Maustaste losgelassen wird, die Kategorien in der neuen Abfolge anordnen
dragdrop.buttonUp = function(sender, MouseEventArgs) {
    
    for(i = 0; i < MSNWidget.categories.length; i++) {
       if(dragdrop.index_in == i){
            MSNWidget.categories.splice(i, 0, MSNWidget.categories[dragdrop.index_out]);
            if(dragdrop.index_in <= dragdrop.index_out)dragdrop.index_out++;
            MSNWidget.categories.splice(dragdrop.index_out, 1);
       }  
    }   
    //ansonsten DragDrop beenden
    News.saveCategories();
}
var Flyout = {};
Flyout.timeout = null;

//Is called, when the silverlight-object from the flyout has been created.
//Stores a reference of the flyout-rootelement in the global variable "flyoutSL"
Flyout.init = function(control, userContext, rootElement){
    flyoutSL = rootElement;
    var choice = MSNWidget.platformConnector.loadSettings("bgColor");
    if(choice == false)choice = 0;
    var bg = flyoutSL.findName("FlyoutBg");
    bg.Fill = config.bg_color[choice];
    MSNWidget.token_flyout = flyoutSL.findName("PreviewLinkText").addEventListener("MouseLeftButtonDown", Flyout.openLink);
    flyoutSL.findName("FlyoutDescription").addEventListener("MouseLeftButtonDown", Flyout.openLink);
    flyoutSL.findName("FlyoutImage").addEventListener("MouseLeftButtonDown", Flyout.openLink);
    
    //Create the flyout-weathersearchbar
    Flyout.weatherSearchBar = new WeatherSearchBar();
    Flyout.weatherSearchBar.init(flyoutSL);
    
    //Create the flyout-weatherscrollbar
    Flyout.scrollbar = new Scrollbar();
    Flyout.scrollbar.init(flyoutSL);
    
    //Initialize the localisation
    flyoutSL.findName("txtLabel1").Text = locale.weather.startSearch;
    
    //Align the "loading"-string vertically & horizontally
    var ldngTxt = flyoutSL.findName("WeatherLoadingTxt");
    ldngTxt.Text = locale.weather.loading;
    ldngTxt["Canvas.Top"] = (flyoutSL.Height / 2) - ( ldngTxt.ActualHeight /2 );
    ldngTxt["Canvas.Left"] = (flyoutSL.Width / 2) - ( ldngTxt.ActualWidth /2 );
    
}

//Shows all the necessary information of the active newsitem 
Flyout.addContentToFlyout = function() {

    if (!MSNWidget.platformConnector.flyoutShow())return;
    
    flyoutSL.findName("WeatherDisplay").Visibility = "Collapsed";
    flyoutSL.findName("FlyoutContent").Visibility = "Visible";
    flyoutSL.findName("WeatherChangeLocationText").Visibility = "Collapsed";

    flyoutSL.findName("PreviewLinkText").Text = (News.isVideo) ? locale.flyout.see_more : locale.news.readmore;
    flyoutSL.findName("PreviewLinkText_bg").Width = flyoutSL.findName("PreviewLinkText").ActualWidth + 12;

    var height = flyoutSL.findName("FlyoutBg").Height - flyoutSL.findName("FlyoutBar").Height - 50;
    
    //If the title-animation is runnining, stop it.
    flyoutSL.findName("ScrollTitle").stop();

    flyoutSL.findName("FlyoutTitle").Text = "-  " + MSNWidget.preview_title[MSNWidget.news].replace(/&amp;/g, "&") + "  -  ";
    flyoutSL.findName("FlyoutTitle")["Canvas.Left"] = -6;
    flyoutSL.findName("FlyoutTitle2").Text = MSNWidget.preview_title[MSNWidget.news].replace(/&amp;/g, "&");;
    flyoutSL.findName("FlyoutTitle2")["Canvas.Left"] = flyoutSL.findName("FlyoutTitle").ActualWidth - 6;
    
    //Set the news-image and its reflection
    if (MSNWidget.preview_img[MSNWidget.news] != ""){
        flyoutSL.findName("FlyoutImage").Source = MSNWidget.preview_img[MSNWidget.news];
        flyoutSL.findName("FlyoutImage_refl").Source = MSNWidget.preview_img[MSNWidget.news];
        if(flyoutSL.findName("FlyoutImage").Height == 0){
            window.setTimeout("Flyout.adjustReflection()", 10);
        } else {
            flyoutSL.findName("FlyoutImage_refl")["Canvas.Top"] = flyoutSL.findName("FlyoutImage").Height + flyoutSL.findName("FlyoutImage")["Canvas.Top"];
        }
    }
    
    //Set the news-text
    if (MSNWidget.preview[MSNWidget.news] == "") flyoutSL.findName("FlyoutDescription").Text = locale.flyout.no_description;
    else {
        var text = MSNWidget.preview[MSNWidget.news];
        flyoutSL.findName("FlyoutDescription").Text = text;
        while(flyoutSL.findName("FlyoutDescription").ActualHeight > height) {
            text = text.substring(0, text.length-5)+"...";
            flyoutSL.findName("FlyoutDescription").Text = text;
        }
    }
        
    if(Flyout.timeout != null)
        window.clearTimeout(Flyout.timeout);
    Flyout.timeout = window.setTimeout("Flyout.scrollTitle()", 500);
    
    MSNWidget.platformConnector.makePageView(MSNWidget.news);
}

Flyout.adjustReflection = function(){
    if(typeof(flyoutSL.findName("FlyoutImage")) == "undefined")
        return;
        
    var img_obj = flyoutSL.findName("FlyoutImage");
    var img_refl = flyoutSL.findName("FlyoutImage_refl");
    if(img_obj.Height == 0 || img_refl.Height == 0){
        window.setTimeout("Flyout.adjustReflection()", 10);
        return;
    } else {
        img_refl["Canvas.Top"] = img_obj.Height + img_obj["Canvas.Top"];
    }
}

//Opens the MSN-page
Flyout.openLink = function(sender, eventArgs){
    if(Weather.visible)
        Weather.openForecast(null, null);
    else
        window.open(MSNWidget.preview_link[MSNWidget.news]);
}


//Scrolls the title across the headline
Flyout.scrollTitle = function(){
    if(!MSNWidget.platformConnector.flyoutShow())
        return;
    var obj_title = flyoutSL.findName("FlyoutTitle");
    var obj_canv = flyoutSL.findName("FlyoutBg");
    var animation = flyoutSL.findName("ScrollTitle");
    var distance = obj_title.ActualWidth;
    var minutes = 0;
    var seconds = Math.ceil(distance / 30);
    if(seconds > 60){
        seconds = seconds % 60;
        minutes = Math.floor(seconds / 60);
    } 
    animation.stop();
    animation.children.getItem(0).KeyFrames.getItem(0).Value = -6;
    animation.children.getItem(0).KeyFrames.getItem(1).Value = (-1)*(distance);
    animation.children.getItem(0).KeyFrames.getItem(1).KeyTime = "0:"+minutes+":"+seconds;
    animation.children.getItem(1).KeyFrames.getItem(0).Value = distance -6;
    animation.children.getItem(1).KeyFrames.getItem(1).Value = 8;
    animation.children.getItem(1).KeyFrames.getItem(1).KeyTime = "0:"+minutes+":"+seconds;
    animation.begin();
}

//Shows the 4-days weather-forecast in the flyout
Flyout.showWeather = function(){

    flyoutSL.findName("WeatherDisplay").Visibility = "Visible";
    flyoutSL.findName("WeatherChangeLocationText").Visibility = "Visible";
    flyoutSL.findName("FlyoutContent").Visibility = "Collapsed";
    flyoutSL.findName("PreviewLinkText").Text = locale.weather.flyout_btn;
    flyoutSL.findName("WeatherChangeLocationText").Text = locale.weather.changeLocation_docked;
    flyoutSL.findName("PreviewLinkText_bg").Width = flyoutSL.findName("PreviewLinkText").ActualWidth + 12;
    
    if(MSNWidget.token_flyout == null){
        MSNWidget.token_flyout = flyoutSL.findName("PreviewLinkText").addEventListener("MouseLeftButtonDown", Flyout.openLink);
        flyoutSL.findName("FlyoutImage").addEventListener("MouseLeftButtonDown", Flyout.openLink);
    }

    flyoutSL.findName("FlyoutTitle").Text = "- "+ locale.weather.flyout_headline + Weather.current.location+" - ";
    flyoutSL.findName("FlyoutTitle2").Text = locale.weather.flyout_headline + Weather.current.location;

    for(var i = 0; i < Weather.forecast.length; i++){
        if(Weather.forecast[i].weatherIcon.sunMoonImg)
		    flyoutSL.findName("Day_"+i+"_SunMoonIcon").Source = Weather.imagePath + Weather.forecast[i].weatherIcon.sunMoonImg;
	    else flyoutSL.findName("Day_"+i+"_SunMoonIcon").Source = "";
		
	    if(Weather.forecast[i].weatherIcon && Weather.forecast[i].weatherIcon.sunMoonRotation)
		    flyoutSL.findName("Day_"+i+"_SunMoonIcon_Rotation").ScaleX = Weather.forecast[i].weatherIcon.sunMoonRotation;
	    else flyoutSL.findName("Day_"+i+"_SunMoonIcon_Rotation").ScaleX= 1;
		
	    if(Weather.forecast[i].weatherIcon.weatherImg.length > 0)
		    flyoutSL.findName("Day_"+i+"_WeatherIcon").Source = Weather.imagePath + Weather.forecast[i].weatherIcon.weatherImg;
	    else flyoutSL.findName("Day_"+i+"_WeatherIcon").Source="";
		
	    if(Weather.forecast[i].skytextday){
		    flyoutSL.findName("Day_"+i+"_Conditions").Text = Weather.forecast[i].skytextday;
		    flyoutSL.findName("Day_"+i+"_Conditions").TextWrapping="Wrap";
	    } else {
		    flyoutSL.findName("Day_"+i+"_Conditions").Text = locale.weather.notAvailable;
		    flyoutSL.findName("Day_"+i+"_Conditions").TextWrapping="Wrap"
	    }
		
	    if(Weather.forecast[i].high)
		    flyoutSL.findName("Day_"+i+"_Hi").Text = Weather.forecast[i].high +unescape("%B0")+ Weather.degreetype;
	    else flyoutSL.findName("Day_"+i+"_Hi").Text = "";
		
	    if(Weather.forecast[i].low)
		    flyoutSL.findName("Day_"+i+"_Lo").Text = Weather.forecast[i].low +unescape("%B0")+ Weather.degreetype;
	    else flyoutSL.findName("Day_"+i+"_Lo").Text = "";
		
	    if(Weather.forecast[i].day)
		    flyoutSL.findName("Day_"+i+"_Day").Text = Weather.forecast[i].day;
	    else flyoutSL.findName("Day_"+i+"_Day").Text = "";
   }
   Flyout.scrollTitle();
}

Flyout.stopTitle = function(){
    var animation = flyoutSL.findName("ScrollTitle");
    var animation2 = flyoutSL.findName("ScrollTitle2");
    animation.stop();
    animation2.stop();
}
</script>

<script type="text/xaml" id="MSN_XAML">
<Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="135" Height="276"
x:Name="root"
RenderTransformOrigin="0.5,0.5" Canvas.Left="1.7" Canvas.Top="1.7" Visibility="Visible">

    <Canvas.Clip>
        <RectangleGeometry x:Name="BgClip" RadiusX="10" RadiusY="10" Rect="0,0,381,276" />
    </Canvas.Clip>

    <Canvas.Resources>

        <Storyboard x:Name="BtnHoverIn" x:Key="BtnHoverIn" Completed="unlock">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="LoadingOut" x:Key="LoadingOut">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Loading" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="LoadingIn" x:Key="LoadingIn">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Loading" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="NewsMove" x:Key="NewsMove" Completed="animCompleted">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Top)" Storyboard.TargetName="NewsItems" >
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="NewsIn" x:Key="NewsIn" Completed="unlock">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="NewsItems" BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.8000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="NewsOut" x:Key="NewsOut" Completed="unlock">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="NewsImgIn" x:Key="NewsImgIn" Completed="news_img_in_completed">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Left)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="-120"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="2"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="NewsImgIn_Scale" x:Key="NewsImgIn_Scale" >
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="Width">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="200"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="100"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Top)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="-50"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>


        <Storyboard x:Name="NewsImgOut" x:Key="NewsImgOut" Completed="news_img_out_completed" >
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Left)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="2"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="150"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="NewsImgOut_Scale" x:Key="NewsImgOut_Scale" >
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="Width">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="100"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Top)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="45"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="BtnHoverOut" x:Key="BtnHoverOut">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Name="BtnPrsd" x:Key="BtnPrsd">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Name="More_In">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="More" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Name="More_Out">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="More" Storyboard.TargetProperty="(UIElement.Opacity)" Completed="collapseMore" >
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="scrollMainCat">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="subcat_text" Storyboard.TargetProperty="(Canvas.Left)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="-300"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="subcat_text2" Storyboard.TargetProperty="(Canvas.Left)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="300"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="innerSubcat" Storyboard.TargetProperty="(Canvas.Left)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="subcat_text" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="subcat_text2" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="Cursor_blink" x:Key="Cursor_blink" RepeatBehavior="Forever">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="SearchBar_Cursor" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Name="SearchBar_More_In" x:Key="SearchBar_More_In">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="SearchBar_More" Storyboard.TargetProperty="(Canvas.Top)" >
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0" KeySpline="0.1,0.7 0.75,1" />
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="-30" KeySpline="0.1,0.7 0.75,1" />
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Name="SearchBar_More_Out">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="SearchBar_More" Storyboard.TargetProperty="(Canvas.Top)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="-30" KeySpline="0.1,0.7 0.75,1" />
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0" KeySpline="0.1,0.7 0.75,1" />
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="Subcats_In">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="SubCats" Storyboard.TargetProperty="(Canvas.Top)" >
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="-30" />
                <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="-20" />
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0" />
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Name="Subcats_Out">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="SubCats" Storyboard.TargetProperty="(Canvas.Top)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0" />
                <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="20" />
                <SplineDoubleKeyFrame KeyTime="00:00:01" Value="30" />
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="rotate_img">
            <DoubleAnimation
       Storyboard.TargetName="Btn_Nachrichten_img_trans"
       Storyboard.TargetProperty="Angle"
       From="0" To="360" Duration="0:0:5" 
       RepeatBehavior="Forever" />
        </Storyboard>

        <Storyboard x:Name="News2Weather" x:Key="News2Weather" Completed="NewsCollapse">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="NewsItemsContainer" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Subcat_Scroll" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="SubCats" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Weather" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="Weather2News" x:Key="Weather2News" Completed="WeatherCollapse">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="NewsItemsContainer" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Subcat_Scroll" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="SubCats" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Weather" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="Weather2Location" x:Key="Weather2Location" Completed="SearchBar_collapse">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="LocationSelection" Storyboard.TargetProperty="(Canvas.Top)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="-250"  KeySpline="0.1,0.7 0.7,0.9"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.8000000" Value="24"  KeySpline="0.1,0.7 0.7,0.9"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="WeatherDisplay" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.8000000" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="SearchBar" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.8000000" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="Location2Weather" x:Key="Location2Weather" >
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="LocationSelection" Storyboard.TargetProperty="(Canvas.Top)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="24"  KeySpline="0.1,0.7 0.7,0.9"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.8000000" Value="-250"  KeySpline="0.1,0.7 0.7,0.9"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="WeatherDisplay" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.8000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="SearchBar" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.8000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

    </Canvas.Resources>

    <Rectangle Width="100" Height="280" x:Name="Page_BG" Fill="#FF000000" RadiusX="5" RadiusY="5" />

    <Canvas Width="135" Height="34" x:Name="Bar" Canvas.Left="0" Canvas.Top="0" Canvas.ZIndex="10">
        <Canvas Width="135" Height="30" Canvas.Left="272" Canvas.Top="0" x:Name="Bar_BG">
            <Rectangle Height="34" Fill="#FF000000" Width="135" x:Name="BarBg" Canvas.Left="-272" Canvas.Top="0"/>
            <Rectangle Width="135" Height="34" x:Name="Bar_Reflektion" Canvas.Left="-272" Canvas.Top="0">
                <Rectangle.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#7FFFFFFF" Offset="0"/>
                        <GradientStop Color="#99FFFFFF" Offset="0.09"/>
                        <GradientStop Color="#7FFFFFFF" Offset="0.11"/>
                        <GradientStop Color="#66FFFFFF" Offset="0.496"/>
                        <GradientStop Color="#26FFFFFF" Offset="0.522"/>
                        <GradientStop Color="#26FFFFFF" Offset="1"/>
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
        </Canvas>

        <Canvas x:Name="Buttons" Width="385" Height="34" Canvas.ZIndex="2">
            <Canvas RenderTransformOrigin="0.5,0.5" Width="17" Height="30" x:Name="Btn_More" Canvas.Left="100" Canvas.Top="2" Canvas.ZIndex="3">
                <Canvas.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="0.6" ScaleY="1"/>
                        <SkewTransform AngleX="0" AngleY="0"/>
                        <RotateTransform Angle="0"/>
                        <TranslateTransform X="0" Y="0"/>
                    </TransformGroup>
                </Canvas.RenderTransform>
                <Rectangle Width="17" Height="30" Stroke="#FF595959" RadiusX="2.7" RadiusY="2">
                    <Rectangle.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#66FFFFFF" Offset="0"/>
                            <GradientStop Color="#E5FFFFFF" Offset="0.058"/>
                            <GradientStop Color="#00FFFFFF" Offset="0.129"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
                <Rectangle Visibility="Visible" x:Name="Btn_More_Hover" Width="17" Height="30" RadiusX="2" RadiusY="2" Stroke="#FF595959" Opacity="0" Cursor="Hand">
                    <Rectangle.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#19FF8200" Offset="0"/>
                            <GradientStop Color="#FFFF8200" Offset="1"/>
                            <GradientStop Color="#7FFF8200" Offset="0.482"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
                <Path Width="15" Height="2" Stretch="Fill" Stroke="#FFD0D0D0" StrokeThickness="2" Data="M3.25,11.583333 L16.166667,11.583333" Canvas.Top="12.696" Canvas.Left="0.354" RenderTransformOrigin="0.151,0.229">
                    <Path.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#66FFFFFF" Offset="0"/>
                            <GradientStop Color="#E5FFFFFF" Offset="0.058"/>
                            <GradientStop Color="#00FFFFFF" Offset="0.129"/>
                        </LinearGradientBrush>
                    </Path.Fill>
                </Path>
                <Path Width="11" Height="2" Stretch="Fill" Stroke="#FFD0D0D0" StrokeThickness="2" Data="M5.6666667,13.333333 L14.630328,13.333333" Canvas.Top="14.696" Canvas.Left="2.238">
                    <Path.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#66FFFFFF" Offset="0"/>
                            <GradientStop Color="#E5FFFFFF" Offset="0.058"/>
                            <GradientStop Color="#00FFFFFF" Offset="0.129"/>
                        </LinearGradientBrush>
                    </Path.Fill>
                </Path>
                <Path Width="5" Height="2" Stretch="Fill" Stroke="#FFD0D0D0" StrokeThickness="2" Data="M9.0833333,15.666667 L12.167793,15.666667" Canvas.Top="16.696" Canvas.Left="5.133">
                    <Path.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#66FFFFFF" Offset="0"/>
                            <GradientStop Color="#E5FFFFFF" Offset="0.058"/>
                            <GradientStop Color="#00FFFFFF" Offset="0.129"/>
                        </LinearGradientBrush>
                    </Path.Fill>
                </Path>
                <Rectangle Visibility="Visible" Name="Btn_More_Prsd" Width="17" Height="30" RadiusX="2" RadiusY="2" Opacity="0" Canvas.ZIndex="1">
                    <Rectangle.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF000000" Offset="0.504"/>
                            <GradientStop Color="#FF222222" Offset="1"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
            </Canvas>

            <Canvas Width="62.524" Height="34" x:Name="Btn_MSN" Canvas.Top="-2.0" Canvas.Left="-2.0" Cursor="Hand" Canvas.ZIndex="5">
                <Ellipse Width="133.333" Height="72.789" Clip="M70.809,20.728 L134.074,20.728 L134.074,54.728 L70.809,54.728 z" Canvas.Top="-19.728" Canvas.Left="-70.809" x:Name="Btn_MSN_Hover" Opacity="0">
                    <Ellipse.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#19FF6E00" Offset="0"/>
                            <GradientStop Color="#FFFF6E00" Offset="1"/>
                            <GradientStop Color="#CCFF6E00" Offset="0.723"/>
                            <GradientStop Color="#5CFF6E00" Offset="0.509"/>
                        </LinearGradientBrush>
                    </Ellipse.Fill>
                </Ellipse>
                <Ellipse Width="133.333" Height="72.789" Clip="M70.809,20.728 L134.074,20.728 L134.074,54.728 L70.809,54.728 z" x:Name="Btn_MSN_Prsd" Canvas.Top="-19.728" Canvas.Left="-70.809" Opacity="0">
                    <Ellipse.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF000000" Offset="0.496"/>
                            <GradientStop Color="#FF222222" Offset="1"/>
                        </LinearGradientBrush>
                    </Ellipse.Fill>
                </Ellipse>
                <Ellipse Width="133.333" Height="72.789" Stroke="#FF000000" Canvas.Top="-19.728" Canvas.Left="-70.809" Clip="M70.809,20.728 L134.074,20.728 L134.074,54.728 L70.809,54.728 z" Cursor="Hand" />
                <Image x:Name="btn_MSN_img" RenderTransformOrigin="0.5,0.5" Width="53.318" Height="19.637" Canvas.Left="3.246" Canvas.Top="7.043" Source="" Stretch="Fill">
                    <Image.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform ScaleX="1" ScaleY="1"/>
                            <SkewTransform AngleX="0" AngleY="0"/>
                            <RotateTransform Angle="0"/>
                            <TranslateTransform X="0" Y="0"/>
                        </TransformGroup>
                    </Image.RenderTransform>
                </Image>
            </Canvas>

            <Canvas Height="34" x:Name="ButtonsCat" Canvas.ZIndex="2" />

        </Canvas>

    </Canvas>


    <Canvas Width="65" Height="34" x:Name="smallWeather" Canvas.Left="100" Canvas.ZIndex="11" Canvas.Top="0" Cursor="Hand" >
        <Canvas.Clip>
            <RectangleGeometry Rect="0,0 65,34"/>
        </Canvas.Clip>
        <Rectangle Width="65" Height="34" x:Name="smallWeather_Btn" Opacity="1">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#7FFFFFFF" Offset="0"/>
                    <GradientStop Color="#26FFFFFF" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle Width="65" Height="34" x:Name="smallWeather_Hover" Opacity="0">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#19FF6E00" Offset="0"/>
                    <GradientStop Color="#FFFF6E00" Offset="1"/>
                    <GradientStop Color="#CCFF6E00" Offset="0.723"/>
                    <GradientStop Color="#5CFF6E00" Offset="0.509"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Image x:Name="smallSunMoonImg" Width="80" Source="" Canvas.Top="-25" Canvas.Left="12" />
        <Image x:Name="smallWeatherImg" Width="80" Source="" Canvas.Top="-25" Canvas.Left="12" />
        <TextBlock x:Name="smallTemperature" FontSize="12" Foreground="#ffffffff" Text="" Canvas.Left="2" Canvas.Top="8" />
</Canvas>

    <Canvas Width="90" Height="180" Canvas.Top="36" x:Name="More" Canvas.ZIndex="11" Visibility="Collapsed">
        <Rectangle x:Name="More_Bg2" Width="100" Height="190" Stroke="#FFAAAAAA" StrokeThickness="1" Canvas.ZIndex="4" RadiusX="2" RadiusY="2">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#88DDDDDD" Offset="0"/>
                    <GradientStop Color="#882D2D2D" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle x:Name="More_Bg" Width="90" Height="180" Canvas.ZIndex="5" RadiusX="2" RadiusY="2" StrokeThickness="0" Opacity="1" Canvas.Left="5" Canvas.Top="5">
            <Rectangle.Fill>
                <RadialGradientBrush>
                    <GradientStop Color="#FF222222" Offset="0"/>
                    <GradientStop Color="#FF000000" Offset="1"/>
                </RadialGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Canvas x:Name="More_Container" Canvas.ZIndex="5" />
    </Canvas>

    <Canvas Width="135" Height="202" Canvas.Top="30" x:Name="Content">

        <Canvas	x:Name="Weather" Canvas.Top="-15" Visibility="Collapsed">

            <Canvas.Resources>
                <Storyboard x:Name="Image_PopUp" x:Key="Image_PopUp" Storyboard.TargetName="Current_SunMoonIcon">
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Width)">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="180"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Left)">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="110"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="20"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>

                <Storyboard x:Name="Image_Slide" x:Key="Image_Slide" Storyboard.TargetName="Current_WeatherIcon">
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Left)">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="100"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="20"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Opacity)">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>

                <Storyboard x:Name="Forecast_SunMoon" x:Key="Forecast_SunMoon" >
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Width)" Storyboard.TargetName="Day_0_SunMoonIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="50"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Left)"  Storyboard.TargetName="Day_0_SunMoonIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="27"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="2"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Left)"  Storyboard.TargetName="Day_0_WeatherIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="50"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="3"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Opacity)"  Storyboard.TargetName="Day_0_WeatherIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.10" Storyboard.TargetProperty="(Width)" Storyboard.TargetName="Day_1_SunMoonIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="50"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.10" Storyboard.TargetProperty="(Canvas.Left)"  Storyboard.TargetName="Day_1_SunMoonIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="27"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="2"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.1" Storyboard.TargetProperty="(Canvas.Left)"  Storyboard.TargetName="Day_1_WeatherIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="50"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="3"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.1" Storyboard.TargetProperty="(Opacity)" Storyboard.TargetName="Day_1_WeatherIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.20" Storyboard.TargetProperty="(Width)" Storyboard.TargetName="Day_2_SunMoonIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="50"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.20" Storyboard.TargetProperty="(Canvas.Left)"  Storyboard.TargetName="Day_2_SunMoonIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="27"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="2"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.20" Storyboard.TargetProperty="(Canvas.Left)"  Storyboard.TargetName="Day_2_WeatherIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="50"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="3"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.2" Storyboard.TargetProperty="(Opacity)" Storyboard.TargetName="Day_2_WeatherIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.30" Storyboard.TargetProperty="(Width)" Storyboard.TargetName="Day_3_SunMoonIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="50"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.30" Storyboard.TargetProperty="(Canvas.Left)"  Storyboard.TargetName="Day_3_SunMoonIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="27"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="2"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.30" Storyboard.TargetProperty="(Canvas.Left)"  Storyboard.TargetName="Day_3_WeatherIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="50"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="3"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.3" Storyboard.TargetProperty="(Opacity)" Storyboard.TargetName="Day_3_WeatherIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.40" Storyboard.TargetProperty="(Width)" Storyboard.TargetName="Day_4_SunMoonIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="50"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.40" Storyboard.TargetProperty="(Canvas.Left)"  Storyboard.TargetName="Day_4_SunMoonIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="27"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="2"/>
                    </DoubleAnimationUsingKeyFrames>

                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.40" Storyboard.TargetProperty="(Canvas.Left)"  Storyboard.TargetName="Day_4_WeatherIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="50"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="3"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.4" Storyboard.TargetProperty="(Opacity)" Storyboard.TargetName="Day_4_WeatherIcon">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>

                <Storyboard x:Name="Image_PopUp_small" x:Key="Image_PopUp_small" Storyboard.TargetName="Current_SunMoonIcon_small">
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Width)">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="180"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Left)">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="110"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="20"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>

                <Storyboard x:Name="Image_Slide_small" x:Key="Image_Slide_small" Storyboard.TargetName="Current_WeatherIcon_small">
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Canvas.Left)">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="100"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="20"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Opacity)">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>

            </Canvas.Resources>


            <Canvas Width="530" Height="296" Canvas.Left="0" Canvas.Top="0" x:Name="WeatherFlyoutBackground" Visibility="Visible">
                <Canvas Width="516" Height="280" Canvas.Left="0" Canvas.Top="0">
                    <Canvas x:Name="cnvBackground" Canvas.Left="0" Canvas.Top="0" Height="280" Width="516"/>
                    <Canvas Width="516" Height="280">
                        <Rectangle Width="516" Height="280">
                            <Rectangle.Fill>
                                <RadialGradientBrush>
                                    <RadialGradientBrush.RelativeTransform>
                                        <TransformGroup>
                                            <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="0.449" ScaleY="0.397"/>
                                            <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                            <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                            <TranslateTransform X="-0.265" Y="-0.24"/>
                                        </TransformGroup>
                                    </RadialGradientBrush.RelativeTransform>
                                    <GradientStop Color="#00FFFFFF" Offset="1"/>
                                    <GradientStop Color="#3FFFFFFF" Offset="0"/>
                                </RadialGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <Rectangle Width="516" Height="280">
                            <Rectangle.Fill>
                                <RadialGradientBrush>
                                    <RadialGradientBrush.RelativeTransform>
                                        <TransformGroup>
                                            <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="0.449" ScaleY="0.397"/>
                                            <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                            <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                            <TranslateTransform X="-0.253" Y="0.298"/>
                                        </TransformGroup>
                                    </RadialGradientBrush.RelativeTransform>
                                    <GradientStop Color="#001F4558" Offset="0.987"/>
                                    <GradientStop Color="#7F1F4558" Offset="0"/>
                                </RadialGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                    </Canvas>

                    <Canvas Width="496" Height="107" x:Name="WeatherDisplay" Canvas.Left="3" Canvas.Top="40" Visibility="Visible">
                        <Image x:Name="Shadow_Menu1" Source="images/weather/shadow_Menu.png" Width="263" Height="201" Canvas.Top="-28" Canvas.Left="-135">
                            <Image.OpacityMask>
                                <RadialGradientBrush>
                                    <RadialGradientBrush.RelativeTransform>
                                        <TransformGroup>
                                            <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="0.861" ScaleY="1.273"/>
                                            <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                            <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                            <TranslateTransform X="0.419" Y="-0.199"/>
                                        </TransformGroup>
                                    </RadialGradientBrush.RelativeTransform>
                                    <GradientStop Color="#FFFF0000" Offset="0"/>
                                    <GradientStop Color="#00FF0000" Offset="1"/>
                                </RadialGradientBrush>
                            </Image.OpacityMask>
                        </Image>

                        <!-- The Large Current part -->

                        <Canvas x:Name="current_large">
                            <Canvas Canvas.Top="0" Canvas.Left="0" Height="107" Width="98" Canvas.ZIndex="1" Background="#00000000" IsHitTestVisible="True" Cursor="Hand" MouseLeftButtonDown="WeatherLocationText_OnMouseDown" />
                            <Canvas Canvas.Top="10" Canvas.Left="98" Height="107" Width="68" Canvas.ZIndex="1" Background="#00000000" IsHitTestVisible="True" Cursor="Hand" MouseLeftButtonDown="WeatherLocationText_OnMouseDown" />
                            <Canvas Width="80" Height="132">
                                <Canvas.OpacityMask>
                                    <RadialGradientBrush>
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.083" ScaleY="1.523"/>
                                                <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                                <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                                <TranslateTransform X="0.369" Y="-0.07"/>
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Color="#FFFF0000" Offset="0.268"/>
                                        <GradientStop Color="#4CFF0000" Offset="0.915"/>
                                    </RadialGradientBrush>
                                </Canvas.OpacityMask>
                                <Canvas Width="80" Height="132" x:Name="Sky_Day_Blue" Visibility="Collapsed">
                                    <Rectangle Width="80" Height="132">
                                        <Rectangle.Fill>
                                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#FF51C7FF" Offset="0"/>
                                                <GradientStop Color="#FFCFEFFF" Offset="1"/>
                                                <GradientStop Color="#FF82D7FF" Offset="0.714"/>
                                            </LinearGradientBrush>
                                        </Rectangle.Fill>
                                    </Rectangle>
                                    <Image x:Name="Sky_Clear1" Source="" Stretch="Fill" Opacity="1" Width="80" Height="132"/>
                                </Canvas>
                                <Canvas x:Name="Sky_Day_Grey" Width="80" Height="132" Visibility="Collapsed">
                                    <Rectangle Width="80" Height="132">
                                        <Rectangle.Fill>
                                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#FF909090" Offset="0"/>
                                                <GradientStop Color="#FFCACACA" Offset="1"/>
                                            </LinearGradientBrush>
                                        </Rectangle.Fill>
                                    </Rectangle>
                                    <Image x:Name="Sky_Cloudy" Source="" Stretch="Fill" Opacity="1" Width="80" Height="132"/>
                                </Canvas>
                                <Canvas x:Name="Sky_Day_Dust" Width="80" Height="132" Visibility="Collapsed">
                                    <Rectangle Width="80" Height="107">
                                        <Rectangle.Fill>
                                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#FF474720" Offset="0"/>
                                                <GradientStop Color="#FFD8D89A" Offset="1"/>
                                            </LinearGradientBrush>
                                        </Rectangle.Fill>
                                    </Rectangle>
                                    <Image x:Name="Sky_Clear2" Source="" Stretch="Fill" Opacity="1" Width="80" Height="132"/>
                                </Canvas>
                                <Canvas x:Name="Sky_Night" Width="80" Height="132" Visibility="Visible">
                                    <Rectangle Width="80" Height="107">
                                        <Rectangle.Fill>
                                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#FF000000" Offset="0"/>
                                                <GradientStop Color="#FF393939" Offset="0.839"/>
                                                <GradientStop Color="#FF000000" Offset="1"/>
                                            </LinearGradientBrush>
                                        </Rectangle.Fill>
                                    </Rectangle>
                                    <Image x:Name="Sky_Stars" Source="" Stretch="Fill" Opacity="0.5" Width="80" Height="132" />
                                </Canvas>
                            </Canvas>
                            <Rectangle Width="80" Height="132">
                                <Rectangle.Stroke>
                                    <RadialGradientBrush>
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.292" ScaleY="1.751"/>
                                                <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                                <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                                <TranslateTransform X="0.015" Y="0.009"/>
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Color="#FFFFFFFF" Offset="0.25"/>
                                        <GradientStop Color="#00FFFFFF" Offset="1"/>
                                    </RadialGradientBrush>
                                </Rectangle.Stroke>
                            </Rectangle>
                            <Image Source="" Width="180" Height="180" Canvas.Left="20" Canvas.Top="-24" x:Name="Current_SunMoonIcon" RenderTransformOrigin="0.5,0.5">
                                <Image.RenderTransform>
                                    <ScaleTransform x:Name="Current_SunMoonIcon_Rotation" ScaleX="1" ScaleY="1"/>
                                </Image.RenderTransform>
                            </Image>
                            <Image Width="180" Source="" Height="180" Canvas.Left="20" Canvas.Top="-24" x:Name="Current_WeatherIcon"/>
                            <Ellipse Width="58" Height="38" Canvas.Top="50">
                                <Ellipse.Fill>
                                    <RadialGradientBrush>
                                        <GradientStop Color="#4C000000" Offset="0"/>
                                        <GradientStop Color="#00000000" Offset="1"/>
                                    </RadialGradientBrush>
                                </Ellipse.Fill>
                            </Ellipse>
                            <Canvas Width="100" Height="36" Canvas.Left="3" Canvas.Top="50">
                                <TextBlock Width="80" Height="36" FontFamily="Arial" FontSize="30" Foreground="#FFDDDDDD" TextWrapping="Wrap" x:Name="Current_Temp" Canvas.Top="-40"/>
          <TextBlock Width="80" Height="29" FontFamily="Arial" Foreground="#FFDDDDDD" TextWrapping="Wrap" Canvas.Top="5">
            <Run FontSize="9" x:Name="Current_FeelsLike_Text" />
            <LineBreak/>
            <Run FontSize="12" x:Name="Current_FeelsLike_Temp" />
          </TextBlock>
        </Canvas>
                            <Canvas Width="70" Height="12" Canvas.Left="8" Canvas.Top="40" Visibility="Collapsed">
                                <TextBlock Width="70" Height="12" FontFamily="Arial" FontSize="10" Foreground="#FFDDDDDD" TextWrapping="Wrap" Opacity="0.5" x:Name="Now"/>
        </Canvas>
                            <Canvas Width="80" Height="50" Canvas.Left="3" Canvas.Top="100">
                                <TextBlock Width="80" Height="50" TextWrapping="Wrap" FontFamily="Arial" FontSize="10" Foreground="#FFDDDDDD" Opacity="0.5" x:Name="Current_Conditions"/>
        </Canvas>
                            <Image Source="images/weather/shadow_Menu.png" x:Name="Shadow_Menu2" Width="263" Height="201" Canvas.Left="137" Canvas.Top="-31">
                                <Image.OpacityMask>
                                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                                        <GradientStop Color="#FFFF0000" Offset="0"/>
                                        <GradientStop Color="#00FF0000" Offset="1"/>
                                    </LinearGradientBrush>
                                </Image.OpacityMask>
                            </Image>
                            <Canvas Width="140" Height="14" Canvas.Left="9" Canvas.Top="140">
                                <TextBlock x:Name="Current_TimeStamp" Width="140" Height="14" FontFamily="Arial" FontSize="10" Foreground="#FFFFFFFF" Opacity="0.35"/>
        </Canvas>
                            <Canvas Width="140" Height="14" Canvas.Left="9" Canvas.Top="154">
                                <TextBlock x:Name="Current_TimeStampLocation" Width="140" Height="14" FontFamily="Arial" FontSize="10" Foreground="#FFFFFFFF" Opacity="0.35"/>
        </Canvas>
                            <Canvas Width="450" Height="14" Canvas.Left="120" Canvas.Top="144">
                                <TextBlock Width="300" Height="14" FontFamily="Arial" FontSize="10" Foreground="#FFFFFFFF" TextWrapping="Wrap" Opacity="0.35" x:Name="Provided_By"/>
        </Canvas>
                        </Canvas>

                        <!-- The small Current canvas -->
                        <Canvas x:Name="current_small">
                            <Canvas Canvas.Top="0" Canvas.Left="0" Height="80" Width="98" Canvas.ZIndex="1" Background="#00000000" IsHitTestVisible="True" Cursor="Hand" MouseLeftButtonDown="WeatherLocationText_OnMouseDown" />
                            <Canvas Canvas.Top="10" Canvas.Left="98" Height="80" Width="68" Canvas.ZIndex="1" Background="#00000000" IsHitTestVisible="True" Cursor="Hand" MouseLeftButtonDown="WeatherLocationText_OnMouseDown" />
                            <Canvas Width="80" Height="90">
                                <Canvas.OpacityMask>
                                    <RadialGradientBrush>
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.083" ScaleY="1.523"/>
                                                <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                                <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                                <TranslateTransform X="0.369" Y="-0.07"/>
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Color="#FFFF0000" Offset="0.268"/>
                                        <GradientStop Color="#4CFF0000" Offset="0.915"/>
                                    </RadialGradientBrush>
                                </Canvas.OpacityMask>
                                <Canvas Width="80" Height="90" x:Name="Sky_Day_Blue_small" Visibility="Collapsed">
                                    <Rectangle Width="80" Height="90">
                                        <Rectangle.Fill>
                                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#FF51C7FF" Offset="0"/>
                                                <GradientStop Color="#FFCFEFFF" Offset="1"/>
                                                <GradientStop Color="#FF82D7FF" Offset="0.714"/>
                                            </LinearGradientBrush>
                                        </Rectangle.Fill>
                                    </Rectangle>
                                    <Image x:Name="Sky_Clear1_small" Source="" Stretch="Fill" Opacity="1" Width="80" Height="90"/>
                                </Canvas>
                                <Canvas x:Name="Sky_Day_Grey_small" Width="80" Height="90" Visibility="Collapsed">
                                    <Rectangle Width="80" Height="90">
                                        <Rectangle.Fill>
                                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#FF909090" Offset="0"/>
                                                <GradientStop Color="#FFCACACA" Offset="1"/>
                                            </LinearGradientBrush>
                                        </Rectangle.Fill>
                                    </Rectangle>
                                    <Image x:Name="Sky_Cloudy_small" Source="" Stretch="Fill" Opacity="1" Width="80" Height="90"/>
                                </Canvas>
                                <Canvas x:Name="Sky_Day_Dust_small" Width="80" Height="90" Visibility="Collapsed">
                                    <Rectangle Width="80" Height="90">
                                        <Rectangle.Fill>
                                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#FF474720" Offset="0"/>
                                                <GradientStop Color="#FFD8D89A" Offset="1"/>
                                            </LinearGradientBrush>
                                        </Rectangle.Fill>
                                    </Rectangle>
                                    <Image x:Name="Sky_Clear2_small" Source="" Stretch="Fill" Opacity="1" Width="80" Height="90"/>
                                </Canvas>
                                <Canvas x:Name="Sky_Night_small" Width="80" Height="90" Visibility="Visible">
                                    <Rectangle Width="80" Height="90">
                                        <Rectangle.Fill>
                                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#FF000000" Offset="0"/>
                                                <GradientStop Color="#FF393939" Offset="0.839"/>
                                                <GradientStop Color="#FF000000" Offset="1"/>
                                            </LinearGradientBrush>
                                        </Rectangle.Fill>
                                    </Rectangle>
                                    <Image x:Name="Sky_Stars_small" Source="" Stretch="Fill" Opacity="0.5" Width="80" Height="90" />
                                </Canvas>
                            </Canvas>
                            <Rectangle Width="80" Height="90">
                                <Rectangle.Stroke>
                                    <RadialGradientBrush>
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.292" ScaleY="1.751"/>
                                                <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                                <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                                <TranslateTransform X="0.015" Y="0.009"/>
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Color="#FFFFFFFF" Offset="0.25"/>
                                        <GradientStop Color="#00FFFFFF" Offset="1"/>
                                    </RadialGradientBrush>
                                </Rectangle.Stroke>
                            </Rectangle>
                            <Image Source="" Width="180" Height="180" Canvas.Left="20" Canvas.Top="-24" x:Name="Current_SunMoonIcon_small" RenderTransformOrigin="0.5,0.5">
                                <Image.RenderTransform>
                                    <ScaleTransform x:Name="Current_SunMoonIcon_Rotation_small" ScaleX="1" ScaleY="1"/>
                                </Image.RenderTransform>
                            </Image>
                            <Image Width="180" Source="" Height="180" Canvas.Left="20" Canvas.Top="-24" x:Name="Current_WeatherIcon_small"/>
                            <Ellipse Width="58" Height="38" Canvas.Top="50">
                                <Ellipse.Fill>
                                    <RadialGradientBrush>
                                        <GradientStop Color="#4C000000" Offset="0"/>
                                        <GradientStop Color="#00000000" Offset="1"/>
                                    </RadialGradientBrush>
                                </Ellipse.Fill>
                            </Ellipse>
                            <Canvas Width="100" Height="36" Canvas.Left="3" Canvas.Top="50">
                                <TextBlock Width="80" Height="36" FontFamily="Arial" FontSize="30" Foreground="#FFDDDDDD" TextWrapping="Wrap" x:Name="Current_Temp_small" Canvas.Top="-50"/>
          <TextBlock Width="80" Height="29" FontFamily="Arial" Foreground="#FFDDDDDD" TextWrapping="Wrap" Canvas.Top="-20">
            <Run FontSize="9" x:Name="Current_FeelsLike_Text_small" />
            <LineBreak/>
            <Run FontSize="12" x:Name="Current_FeelsLike_Temp_small" />
          </TextBlock>
        </Canvas>
                            <Canvas Width="70" Height="12" Canvas.Left="8" Canvas.Top="40" Visibility="Collapsed">
                                <TextBlock Width="70" Height="12" FontFamily="Arial" FontSize="10" Foreground="#FFDDDDDD" TextWrapping="Wrap" Opacity="0.5" x:Name="Now_small"/>
        </Canvas>
                            <Canvas Width="80" Height="50" Canvas.Left="3" Canvas.Top="70">
                                <TextBlock Width="80" Height="50" TextWrapping="Wrap" FontFamily="Arial" FontSize="10" Foreground="#FFDDDDDD" Opacity="0.5" x:Name="Current_Conditions_small"/>
        </Canvas>
                            <Image Source="images/weather/shadow_Menu.png" x:Name="Shadow_Menu2_small" Width="263" Height="201" Canvas.Left="137" Canvas.Top="-31">
                                <Image.OpacityMask>
                                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                                        <GradientStop Color="#FFFF0000" Offset="0"/>
                                        <GradientStop Color="#00FF0000" Offset="1"/>
                                    </LinearGradientBrush>
                                </Image.OpacityMask>
                            </Image>
                            <Canvas Width="140" Height="14" Canvas.Left="9" Canvas.Top="140">
                                <TextBlock x:Name="Current_TimeStamp_small" Width="140" Height="14" FontFamily="Arial" FontSize="10" Foreground="#FFFFFFFF" Opacity="0.35"/>
        </Canvas>
                            <Canvas Width="140" Height="14" Canvas.Left="9" Canvas.Top="95">
                                <TextBlock x:Name="Current_TimeStampLocation_small" Width="140" Height="14" FontFamily="Arial" FontSize="10" Foreground="#FFFFFFFF" Opacity="0.35"/>
        </Canvas>
                            <Canvas Width="450" Height="14" Canvas.Left="120" Canvas.Top="144">
                                <TextBlock Width="300" Height="14" FontFamily="Arial" FontSize="10" Foreground="#FFFFFFFF" TextWrapping="Wrap" Opacity="0.35" x:Name="Provided_By_small"/>
        </Canvas>
                        </Canvas>

                        <Canvas  x:Name="Forecast_Canvas" Cursor="Hand">
                            <Canvas Width="57" Height="132" Canvas.Left="142" Canvas.Top="0" Background="#00000000" IsHitTestVisible="True" Cursor="Hand">
                                <Rectangle Width="57" Height="132">
                                    <Rectangle.Stroke>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.654" ScaleY="1.33"/>
                                                    <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                                    <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                                    <TranslateTransform X="-0.029" Y="0.003"/>
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFFFFFFF" Offset="0"/>
                                            <GradientStop Color="#00FFFFFF" Offset="1"/>
                                        </RadialGradientBrush>
                                    </Rectangle.Stroke>
                                    <Rectangle.Fill>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FF000000" Offset="0"/>
                                            <GradientStop Color="#FF141414" Offset="1"/>
                                            <GradientStop Color="#FF353535" Offset="0.835"/>
                                        </LinearGradientBrush>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <Image Source="" Width="50" Height="50" Canvas.Top="-4" Canvas.Left="2" x:Name="Day_0_SunMoonIcon">
                                    <Image.RenderTransform>
                                        <ScaleTransform x:Name="Day_0_SunMoonIcon_Rotation" ScaleX="1" ScaleY="1"/>
                                    </Image.RenderTransform>
                                </Image>
                                <Image Source="" Width="50" Height="50" Canvas.Top="-4" Canvas.Left="2" x:Name="Day_0_WeatherIcon"/>
                                <Canvas Width="56" Height="26" Canvas.Left="2" Canvas.Top="104">
                                    <Canvas.Clip>
                                        <RectangleGeometry Rect="0,0 51,24"/>
                                    </Canvas.Clip>
                                    <TextBlock Width="56" Height="26" FontFamily="Arial" FontSize="9" Foreground="#FFFFFFFF" Opacity="0.5" x:Name="Day_0_Conditions"/>
          </Canvas>
                                <TextBlock Width="50" Height="22" Canvas.Left="3" Canvas.Top="58" FontFamily="Arial" FontSize="18" Foreground="#FFFFFFFF" TextWrapping="NoWrap" x:Name="Day_0_Hi" />
          <TextBlock Width="50" Height="22" Canvas.Left="3" Canvas.Top="83" FontFamily="Arial" FontSize="14" Foreground="#7FFFFFFF" TextWrapping="NoWrap" x:Name="Day_0_Lo"/>
          <TextBlock Width="48" Height="16" Canvas.Left="3" Canvas.Top="44" FontFamily="Arial" FontSize="9" Foreground="#FFFFFFFF" TextWrapping="NoWrap" Opacity="0.5" x:Name="Day_0_Day"/>
        </Canvas>
                            <Canvas Width="57" Height="132" Canvas.Left="200" Canvas.Top="0" Background="#00000000" IsHitTestVisible="True" Cursor="Hand" MouseLeftButtonDown="WeatherLocationForecast_OnMouseDown">
                                <Rectangle Width="57" Height="132">
                                    <Rectangle.Fill>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FF000000" Offset="0"/>
                                            <GradientStop Color="#FF141414" Offset="1"/>
                                            <GradientStop Color="#FF353535" Offset="0.835"/>
                                        </LinearGradientBrush>
                                    </Rectangle.Fill>
                                    <Rectangle.Stroke>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.654" ScaleY="1.33"/>
                                                    <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                                    <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                                    <TranslateTransform X="-0.029" Y="0.003"/>
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFFFFFFF" Offset="0"/>
                                            <GradientStop Color="#00FFFFFF" Offset="1"/>
                                        </RadialGradientBrush>
                                    </Rectangle.Stroke>
                                </Rectangle>
                                <Image Source="" Width="50" Height="50" Canvas.Top="-4" Canvas.Left="2" x:Name="Day_1_SunMoonIcon">
                                    <Image.RenderTransform>
                                        <ScaleTransform x:Name="Day_1_SunMoonIcon_Rotation" ScaleX="1" ScaleY="1"/>
                                    </Image.RenderTransform>
                                </Image>
                                <Image Source="" Width="50" Height="50" Canvas.Top="-4" Canvas.Left="2" x:Name="Day_1_WeatherIcon"/>
                                <Canvas Width="56" Height="26" Canvas.Left="3" Canvas.Top="104">
                                    <Canvas.Clip>
                                        <RectangleGeometry Rect="0,0 56,24"/>
                                    </Canvas.Clip>
                                    <TextBlock Width="56" Height="26" FontFamily="Arial" FontSize="9" Foreground="#FFFFFFFF" Opacity="0.5" x:Name="Day_1_Conditions"/>
          </Canvas>
                                <TextBlock Width="50" Height="22" Canvas.Left="3" Canvas.Top="58" FontFamily="Arial" FontSize="18" Foreground="#FFFFFFFF" TextWrapping="NoWrap" x:Name="Day_1_Hi"/>
          <TextBlock Width="50" Height="22" Canvas.Left="3" Canvas.Top="83" FontFamily="Arial" FontSize="14" Foreground="#7FFFFFFF" TextWrapping="NoWrap" x:Name="Day_1_Lo"/>
          <TextBlock Width="48" Height="16" Canvas.Left="3" Canvas.Top="44" FontFamily="Arial" FontSize="9.5" Foreground="#FFFFFFFF" TextWrapping="NoWrap" Opacity="0.5" x:Name="Day_1_Day"/>
        </Canvas>
                            <Canvas Width="57" Height="132" Canvas.Left="258" Canvas.Top="0" Background="#00000000" IsHitTestVisible="True" Cursor="Hand" MouseLeftButtonDown="WeatherLocationForecast_OnMouseDown">
                                <Rectangle Width="57" Height="132">
                                    <Rectangle.Fill>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FF000000" Offset="0"/>
                                            <GradientStop Color="#FF141414" Offset="1"/>
                                            <GradientStop Color="#FF353535" Offset="0.835"/>
                                        </LinearGradientBrush>
                                    </Rectangle.Fill>
                                    <Rectangle.Stroke>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.654" ScaleY="1.33"/>
                                                    <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                                    <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                                    <TranslateTransform X="-0.029" Y="0.003"/>
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFFFFFFF" Offset="0"/>
                                            <GradientStop Color="#00FFFFFF" Offset="1"/>
                                        </RadialGradientBrush>
                                    </Rectangle.Stroke>
                                </Rectangle>
                                <Image Source="" Width="50" Height="50" Canvas.Top="-4" Canvas.Left="2" x:Name="Day_2_SunMoonIcon">
                                    <Image.RenderTransform>
                                        <ScaleTransform x:Name="Day_2_SunMoonIcon_Rotation" ScaleX="1" ScaleY="1"/>
                                    </Image.RenderTransform>
                                </Image>
                                <Image Source="" Width="56" Height="50" Canvas.Top="-4" Canvas.Left="2" x:Name="Day_2_WeatherIcon"/>
                                <Canvas Width="56" Height="26" Canvas.Left="3" Canvas.Top="104">
                                    <Canvas.Clip>
                                        <RectangleGeometry Rect="0,0 56,24"/>
                                    </Canvas.Clip>
                                    <TextBlock Width="56" Height="26" FontFamily="Arial" FontSize="9" Foreground="#FFFFFFFF" Opacity="0.5" x:Name="Day_2_Conditions"/>
          </Canvas>
                                <TextBlock Width="50" Height="22" Canvas.Left="3" Canvas.Top="58" FontFamily="Arial" FontSize="18" Foreground="#FFFFFFFF" TextWrapping="NoWrap" x:Name="Day_2_Hi"/>
          <TextBlock Width="50" Height="22" Canvas.Left="3" Canvas.Top="83" FontFamily="Arial" FontSize="14" Foreground="#7FFFFFFF" TextWrapping="NoWrap" x:Name="Day_2_Lo"/>
          <TextBlock Width="48" Height="16" Canvas.Left="3" Canvas.Top="44" FontFamily="Arial" FontSize="9.5" Foreground="#FFFFFFFF" TextWrapping="NoWrap" Opacity="0.5" x:Name="Day_2_Day"/>
        </Canvas>
                            <Canvas Width="57" Height="132" Canvas.Left="316" Canvas.Top="0" Background="#00000000" IsHitTestVisible="True" Cursor="Hand" MouseLeftButtonDown="WeatherLocationForecast_OnMouseDown">
                                <Rectangle Width="57" Height="132">
                                    <Rectangle.Fill>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FF000000" Offset="0"/>
                                            <GradientStop Color="#FF141414" Offset="1"/>
                                            <GradientStop Color="#FF353535" Offset="0.835"/>
                                        </LinearGradientBrush>
                                    </Rectangle.Fill>
                                    <Rectangle.Stroke>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.654" ScaleY="1.33"/>
                                                    <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                                    <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                                    <TranslateTransform X="-0.029" Y="0.003"/>
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFFFFFFF" Offset="0"/>
                                            <GradientStop Color="#00FFFFFF" Offset="1"/>
                                        </RadialGradientBrush>
                                    </Rectangle.Stroke>
                                </Rectangle>
                                <Image Source="" Width="50" Height="50" Canvas.Top="-4" Canvas.Left="2" x:Name="Day_3_SunMoonIcon">
                                    <Image.RenderTransform>
                                        <ScaleTransform x:Name="Day_3_SunMoonIcon_Rotation" ScaleX="1" ScaleY="1"/>
                                    </Image.RenderTransform>
                                </Image>
                                <Image Source="" Width="50" Height="50" Canvas.Top="-4" Canvas.Left="2" x:Name="Day_3_WeatherIcon"/>
                                <Canvas Width="56" Height="26" Canvas.Left="5" Canvas.Top="104">
                                    <Canvas.Clip>
                                        <RectangleGeometry Rect="0,0 56,24"/>
                                    </Canvas.Clip>
                                    <TextBlock Width="56" Height="26" FontFamily="Arial" FontSize="9" Foreground="#FFFFFFFF" Opacity="0.5" x:Name="Day_3_Conditions"/>
          </Canvas>
                                <TextBlock Width="50" Height="22" Canvas.Left="3" Canvas.Top="58" FontFamily="Arial" FontSize="18" Foreground="#FFFFFFFF" TextWrapping="NoWrap" x:Name="Day_3_Hi"/>
          <TextBlock Width="50" Height="22" Canvas.Left="3" Canvas.Top="83" FontFamily="Arial" FontSize="14" Foreground="#7FFFFFFF" TextWrapping="NoWrap" x:Name="Day_3_Lo"/>
          <TextBlock Width="48" Height="16" Canvas.Left="3" Canvas.Top="44" FontFamily="Arial" FontSize="9.5" Foreground="#FFFFFFFF" TextWrapping="NoWrap" Opacity="0.5" x:Name="Day_3_Day"/>
        </Canvas>
                            <Canvas Width="55" Height="132" Canvas.Left="410" Canvas.Top="0" Background="#00000000" IsHitTestVisible="True" Cursor="Hand" MouseLeftButtonDown="WeatherLocationForecast_OnMouseDown">
                                <Rectangle Width="64" Height="132">
                                    <Rectangle.Fill>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FF000000" Offset="0"/>
                                            <GradientStop Color="#FF141414" Offset="1"/>
                                            <GradientStop Color="#FF353535" Offset="0.835"/>
                                        </LinearGradientBrush>
                                    </Rectangle.Fill>
                                    <Rectangle.Stroke>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.654" ScaleY="1.33"/>
                                                    <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                                    <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                                    <TranslateTransform X="-0.029" Y="0.003"/>
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#FFFFFFFF" Offset="0"/>
                                            <GradientStop Color="#00FFFFFF" Offset="1"/>
                                        </RadialGradientBrush>
                                    </Rectangle.Stroke>
                                </Rectangle>
                                <Image Source="" Width="44" Height="44" Canvas.Left="10" x:Name="Day_4_SunMoonIcon">
                                    <Image.RenderTransform>
                                        <ScaleTransform x:Name="Day_4_SunMoonIcon_Rotation" ScaleX="1" ScaleY="1"/>
                                    </Image.RenderTransform>
                                </Image>
                                <Image Source="" Width="44" Height="44" Canvas.Left="10" x:Name="Day_4_WeatherIcon"/>
                                <Canvas Width="54" Height="26" Canvas.Left="5" Canvas.Top="104">
                                    <Canvas.Clip>
                                        <RectangleGeometry Rect="0,0 51,24"/>
                                    </Canvas.Clip>
                                    <TextBlock Width="56" Height="26" FontFamily="Arial" FontSize="9" Foreground="#FFFFFFFF" Opacity="0.5" x:Name="Day_4_Conditions"/>
          </Canvas>
                                <TextBlock Width="50" Height="22" Canvas.Left="8" Canvas.Top="58" FontFamily="Arial" FontSize="20" Foreground="#FFFFFFFF" TextWrapping="NoWrap" x:Name="Day_4_Hi"/>
          <TextBlock Width="50" Height="22" Canvas.Left="8" Canvas.Top="83" FontFamily="Arial" FontSize="14" Foreground="#7FFFFFFF" TextWrapping="NoWrap" x:Name="Day_4_Lo"/>
          <TextBlock Width="48" Height="16" Canvas.Left="8" Canvas.Top="44" FontFamily="Arial" FontSize="9.5" Foreground="#FFFFFFFF" TextWrapping="NoWrap" Opacity="0.5" x:Name="Day_4_Day"/>
        </Canvas>
                        </Canvas>

                        <Canvas Width="385" Height="34" Canvas.Left="0" Canvas.Top="-47">
                            <TextBlock Width="320" Height="12" FontFamily="Arial" FontSize="10" Foreground="#FFFFFFFF" Text="" TextWrapping="Wrap" Opacity="0.5" Canvas.Left="0" Canvas.Top="22" x:Name="Weather_Close" Cursor="Hand"/>
          <TextBlock Width="320" Height="12" FontFamily="Arial" FontSize="10" Foreground="#FFFFFFFF" Text="" TextWrapping="Wrap" Opacity="0.5" Canvas.Left="0" Canvas.Top="22" x:Name="Weather_ChangeLocation" Cursor="Hand"/>
          <Canvas Width="320" Height="20">
            <TextBlock Width="300" Height="20" FontFamily="Arial" FontSize="14" Foreground="#FFFFFFFF" Text="" TextWrapping="Wrap" Opacity="1" x:Name="Current_Location" Cursor="Hand" MouseEnter="WeatherLocation_OnMouseEnter" MouseLeave="WeatherLocation_OnMouseLeave" MouseLeftButtonDown="WeatherLocationText_OnMouseDown" />
          </Canvas>
        </Canvas>
                        <Canvas Width="496" Height="23" Canvas.Top="170">
                            <Canvas x:Name="FlyoutSearchBlock">
                            </Canvas>
                        </Canvas>
                        <Canvas Width="100" Height="17" Canvas.Top="142" Canvas.Left="270" Visibility="Collapsed">
                            <Canvas Width="17" Height="17" Canvas.Left="34">
                                <Ellipse Width="11" Height="11" Canvas.Left="3" Canvas.Top="3" Stroke="#FF666666" x:Name="Radial_F" MouseLeftButtonUp="setDegreeType" MouseEnter="Radial_RollOver" MouseLeave="Radial_RollOut" Cursor="Hand">
                                    <Ellipse.Fill>
                                        <RadialGradientBrush>
                                            <GradientStop Color="#FF545454" Offset="0"/>
                                            <GradientStop Color="#FF000000" Offset="1"/>
                                        </RadialGradientBrush>
                                    </Ellipse.Fill>
                                </Ellipse>
                                <Canvas Width="17" Height="17" x:Name="Radial_F_Selected" Visibility="Collapsed" IsHitTestVisible="False">
                                    <Ellipse Width="17" Height="17">
                                        <Ellipse.Fill>
                                            <RadialGradientBrush>
                                                <GradientStop Color="#B2FFFFFF" Offset="0"/>
                                                <GradientStop Color="#00FFFFFF" Offset="1"/>
                                            </RadialGradientBrush>
                                        </Ellipse.Fill>
                                    </Ellipse>
                                    <Ellipse Width="5" Height="5" Canvas.Left="6" Canvas.Top="6" Stroke="#FFFFFFFF">
                                        <Ellipse.Fill>
                                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#FFFFFFFF" Offset="0"/>
                                                <GradientStop Color="#FFC8C8C8" Offset="1"/>
                                            </LinearGradientBrush>
                                        </Ellipse.Fill>
                                    </Ellipse>
                                </Canvas>
                                <TextBlock Width="17" Height="12" Text="F" TextWrapping="Wrap" Foreground="#FFCCCCCC" FontSize="11" Canvas.Left="19" FontFamily="Arial" Canvas.Top="2"/>
          </Canvas>
                            <Canvas Width="17" Height="17" Canvas.Left="69">
                                <Ellipse Width="11" Height="11" Stroke="#FF666666" Canvas.Left="3" Canvas.Top="3" x:Name="Radial_C" MouseLeftButtonUp="setDegreeType" MouseEnter="Radial_RollOver" MouseLeave="Radial_RollOut" Cursor="Hand">
                                    <Ellipse.Fill>
                                        <RadialGradientBrush>
                                            <GradientStop Color="#FF545454" Offset="0"/>
                                            <GradientStop Color="#FF000000" Offset="1"/>
                                        </RadialGradientBrush>
                                    </Ellipse.Fill>
                                </Ellipse>
                                <Canvas x:Name="Radial_C_Selected" Width="17" Height="17" Visibility="Visible" IsHitTestVisible="False">
                                    <Ellipse Width="17" Height="17">
                                        <Ellipse.Fill>
                                            <RadialGradientBrush>
                                                <GradientStop Color="#B2FFFFFF" Offset="0"/>
                                                <GradientStop Color="#00FFFFFF" Offset="1"/>
                                            </RadialGradientBrush>
                                        </Ellipse.Fill>
                                    </Ellipse>
                                    <Ellipse Width="5" Height="5" Stroke="#FFFFFFFF" Canvas.Left="6" Canvas.Top="6">
                                        <Ellipse.Fill>
                                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#FFFFFFFF" Offset="0"/>
                                                <GradientStop Color="#FFC8C8C8" Offset="1"/>
                                            </LinearGradientBrush>
                                        </Ellipse.Fill>
                                    </Ellipse>
                                </Canvas>
                                <TextBlock Width="17" Height="12" Canvas.Left="19" Canvas.Top="2" FontFamily="Arial" FontSize="11" Foreground="#FFCCCCCC" Text="C" TextWrapping="Wrap"/>
          </Canvas>
                        </Canvas>
                    </Canvas>
                    <Canvas Width="496" Height="198" x:Name="LocationSelection" Visibility="Collapsed" Canvas.Left="10" Canvas.Top="-220">
                        <Image Source="images/weather/shadow_Menu.png" x:Name="Shadow_Menu3" Width="536" Height="172" Canvas.Left="-20" Canvas.Top="10" Stretch="Fill"/>
                        <Rectangle x:Name="LocationSelectionBg" Opacity="0.6" Width="496" Height="162" Canvas.Left="0" Canvas.Top="36">
                            <Rectangle.Stroke>
                                <RadialGradientBrush>
                                    <RadialGradientBrush.RelativeTransform>
                                        <TransformGroup>
                                            <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.378" ScaleY="1.378"/>
                                            <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                            <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                            <TranslateTransform X="0" Y="-0.004"/>
                                        </TransformGroup>
                                    </RadialGradientBrush.RelativeTransform>
                                    <GradientStop Color="#33FFFFFF" Offset="1"/>
                                    <GradientStop Color="#FFFFFFFF" Offset="0.357"/>
                                </RadialGradientBrush>
                            </Rectangle.Stroke>
                            <Rectangle.Fill>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#CC000000" Offset="0"/>
                                    <GradientStop Color="#CC121212" Offset="1"/>
                                    <GradientStop Color="#CC1E1E1E" Offset="0.741"/>
                                </LinearGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <Canvas Width="496" Height="23">
                            <Canvas x:Name="FlyoutSearchBlock_Copy">
                                <!-- SEARCH BUTTON -->
                                <!-- END SEARCH BUTTON -->
                                <!-- SEARCH BOX -->
                                <Canvas x:Name="cnvTextBox1" Height="22" Width="424" Background="Transparent">
                                    <TextBox x:Name='WeatherSearchBox' Canvas.Top='-4' Text="" Height="25" FontSize='14' />
                                </Canvas>
                                <Canvas x:Name="cnvWeatherLocation" Width="77" Height="20" Canvas.Left="300" Cursor="Hand" >
                                    <Canvas.Resources>
                                        <Storyboard x:Name="sb_location_in">
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="cnvSBDown1" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="0"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="cnvSBRollover1" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                        <Storyboard x:Name="sb_location_out">
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="cnvSBDown1" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.3500000" Value="0"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="cnvSBRollover1" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.3500000" Value="0"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                        <Storyboard x:Name="sb_location_down">
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="cnvSBDown1" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.0500000" Value="1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                        <Storyboard x:Name="sb_location_up">
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="cnvSBDown1" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.2500000" Value="0"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </Canvas.Resources>
                                    <Canvas x:Name="cnvSBNormal1" Width="77" Height="18" Canvas.Top="0">
                                        <Rectangle x:Name="rectNormal1" RadiusX="2" RadiusY="2" Width="77" Height="18" Stroke="#FFFFFFFF" Opacity="1">
                                            <Rectangle.Fill>
                                                <LinearGradientBrush EndPoint="0.487,0.032" StartPoint="0.487,0.968">
                                                    <GradientStop Color="#FFD0E2F0" Offset="0.507"/>
                                                    <GradientStop Color="#FFFFFFFF" Offset="0.532"/>
                                                    <GradientStop Color="#FFFFFFFF" Offset="0"/>
                                                    <GradientStop Color="#FFFFFFFF" Offset="1"/>
                                                </LinearGradientBrush>
                                            </Rectangle.Fill>
                                        </Rectangle>
                                    </Canvas>
                                    <Canvas x:Name="cnvSBRollover1" Width="77" Height="18" Opacity="0" Canvas.Top="0">
                                        <Rectangle x:Name="rectRollover1" RadiusX="2" RadiusY="2" Width="77" Height="18" Stroke="#FFFFFFFF" Opacity="1">
                                            <Rectangle.Fill>
                                                <LinearGradientBrush EndPoint="0.487,0.032" StartPoint="0.487,0.968">
                                                    <GradientStop Color="#FFD0E2F0" Offset="0.507"/>
                                                    <GradientStop Color="#FFFFFFFF" Offset="0.532"/>
                                                    <GradientStop Color="#FFFF9044" Offset="0"/>
                                                    <GradientStop Color="#FFFFFFFF" Offset="1"/>
                                                </LinearGradientBrush>
                                            </Rectangle.Fill>
                                        </Rectangle>
                                    </Canvas>
                                    <Canvas x:Name="cnvSBDown1" Width="77" Height="18" Opacity="0" Canvas.Top="0">
                                        <Rectangle x:Name="rectDown1" RadiusX="2" RadiusY="2" Width="77" Height="18" Stroke="#FF4D4D4D" Opacity="1">
                                            <Rectangle.Fill>
                                                <LinearGradientBrush EndPoint="0.487,0.032" StartPoint="0.487,0.968">
                                                    <GradientStop Color="#FF848484" Offset="0.507"/>
                                                    <GradientStop Color="#FF9F9F9F" Offset="0.532"/>
                                                    <GradientStop Color="#FF7E7E7E" Offset="0"/>
                                                    <GradientStop Color="#FFC5C5C5" Offset="1"/>
                                                </LinearGradientBrush>
                                            </Rectangle.Fill>
                                        </Rectangle>
                                    </Canvas>
                                    <TextBlock x:Name="txtLabel1" Canvas.Left="8" Canvas.Top="2" Height="15" FontFamily="Verdana" FontSize="11" Text="" TextWrapping="NoWrap" Foreground="#FF07519A"/>
            </Canvas>
                                <!-- END SEARCH BOX-->
                            </Canvas>
                        </Canvas>
                        <Canvas Width="494" Height="160" Canvas.Left="1" Canvas.Top="37" x:Name="cnvScroll1">
                            <Canvas Width="17" Height="158" Canvas.Left="476" Canvas.Top="1" x:Name="cnvScroll2">
                                <Canvas.Background>
                                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                                        <GradientStop Color="#FF000000" Offset="0"/>
                                        <GradientStop Color="#FF2E2E2E" Offset="0.415"/>
                                    </LinearGradientBrush>
                                </Canvas.Background>
                                <Canvas.OpacityMask>
                                    <RadialGradientBrush>
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.957" ScaleY="1"/>
                                                <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                                <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                                <TranslateTransform X="-0.772" Y="-0.001"/>
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Color="#FFFF0000" Offset="0"/>
                                        <GradientStop Color="#B2FF0000" Offset="1"/>
                                    </RadialGradientBrush>
                                </Canvas.OpacityMask>
                                <Canvas x:Name="ScrollArrowUp" Width="17" Height="13" Background="#00FFFFFF" Cursor="Hand">
                                    <Path Height="5" Width="9" Stretch="Fill" Opacity="1" Data="M 525,83 C525,83 521,88 521,88 521,88 529,88 529,88 529,88 525,83 525,83 z" Fill="#FFFFFFFF" Canvas.Left="4" Canvas.Top="4" />
                                </Canvas>
                                <Canvas x:Name="ScrollBar" Width="15" Height="132" Canvas.Top="13" Canvas.Left="0">
                                    <Rectangle x:Name="ScrollGripper" Width="15" Height="30" Fill="#FF888888" Stroke="#FFCCCCCC" RadiusX="2" RadiusY="2" Cursor="Hand">
                                        <Rectangle.OpacityMask>
                                            <LinearGradientBrush EndPoint="0,0.5" StartPoint="1,0.5">
                                                <GradientStop Color="#FFFF0000" Offset="0.482"/>
                                                <GradientStop Color="#00FF0000" Offset="0.808"/>
                                            </LinearGradientBrush>
                                        </Rectangle.OpacityMask>
                                    </Rectangle>
                                </Canvas>
                                <Canvas x:Name="ScrollArrowDown" Width="17" Height="13" Canvas.Left="0" Canvas.Top="145" Cursor="Hand">
                                    <Path Height="5" Width="9" Stretch="Fill" Opacity="1" Data="M 525,83 C525,83 521,88 521,88 521,88 529,88 529,88 529,88 525,83 525,83 z" Fill="#FFFFFFFF" RenderTransformOrigin="0.5,0.5" Canvas.Left="4" Canvas.Top="4" >
                                        <Path.RenderTransform>
                                            <TransformGroup>
                                                <ScaleTransform ScaleX="1" ScaleY="-1"/>
                                            </TransformGroup>
                                        </Path.RenderTransform>
                                    </Path>
                                </Canvas>
                            </Canvas>

                            <Canvas x:Name="ScrollContent" Width="474" Height="156" Canvas.Left="1" Canvas.Top="1" >
                                <Canvas.Clip>
                                    <RectangleGeometry x:Name="ScrollClip" Rect="0,0,474,158" />
                                </Canvas.Clip>
                                <Canvas x:Name="WeatherContent" Width="474" Height="156" Canvas.Left="0" Canvas.Top="0"/>
                            </Canvas>


                            <Canvas Width="320" Height="34" Canvas.Left="0" Canvas.Top="-40">
                                <TextBlock Canvas.Top="6" Cursor="IBeam" Canvas.Left="5" Width="320" Height="20" FontFamily="Arial" FontSize="12" Foreground="#FF999999" Text="" TextWrapping="Wrap" Opacity="1" x:Name="SearchForYourLocation"/>
          <TextBlock Width="320" Height="12" FontFamily="Arial" FontSize="10" Foreground="#FFFFFFFF" Text="[ cancel ]" TextWrapping="Wrap" Opacity="0.5" x:Name="Weather_CancelChangeLocation" MouseLeftButtonUp="Weather_Click" MouseEnter="Weather_RollOver" MouseLeave="Weather_RollOut" Cursor="Hand" Canvas.Top="25"/>
          <TextBlock Width="320" Height="12" FontFamily="Arial" FontSize="10" Foreground="#FFFFFFFF" Text="[ clear location history ]" TextWrapping="Wrap" Opacity="0.5" x:Name="Weather_ClearChangeLocation" MouseLeftButtonUp="Weather_Click" MouseEnter="Weather_RollOver" MouseLeave="Weather_RollOut" Cursor="Hand" Canvas.Top="25"/>
        </Canvas>

                            <Canvas Width="516" Height="280" x:Name="WeatherNoService" Canvas.Left="0" Visibility="Collapsed">
                                <Rectangle Width="516" Height="248" Canvas.Top="32">
                                    <Rectangle.Fill>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#00000000" Offset="0"/>
                                            <GradientStop Color="#CC000000" Offset="0.411"/>
                                        </LinearGradientBrush>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <Rectangle Width="516" Height="248" Canvas.Top="32">
                                    <Rectangle.Fill>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.157" ScaleY="1.156"/>
                                                    <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                                    <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                                    <TranslateTransform X="0.428" Y="0.254"/>
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#000F222B" Offset="1"/>
                                            <GradientStop Color="#FF0F222B" Offset="0"/>
                                        </RadialGradientBrush>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <Image Source="" Width="531" Height="182" Canvas.Left="-8" x:Name="WeatherNoServiceImage1" Canvas.Top="90" Opacity="0.3"/>
                                <Rectangle Width="516" Height="248" Canvas.Top="32">
                                    <Rectangle.Fill>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="0.787" ScaleY="0.785"/>
                                                    <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                                    <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                                    <TranslateTransform X="-0.176" Y="0.534"/>
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#000F222B" Offset="1"/>
                                            <GradientStop Color="#7F0F222B" Offset="0"/>
                                        </RadialGradientBrush>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <Rectangle Width="516" Height="248" Canvas.Top="32">
                                    <Rectangle.Fill>
                                        <RadialGradientBrush>
                                            <RadialGradientBrush.RelativeTransform>
                                                <TransformGroup>
                                                    <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.157" ScaleY="1.156"/>
                                                    <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                                    <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                                    <TranslateTransform X="-0.779" Y="0.186"/>
                                                </TransformGroup>
                                            </RadialGradientBrush.RelativeTransform>
                                            <GradientStop Color="#000F222B" Offset="1"/>
                                            <GradientStop Color="#FF0F222B" Offset="0"/>
                                        </RadialGradientBrush>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <TextBlock Width="374" Height="123" Canvas.Left="111" Canvas.Top="139" Foreground="#FFFFFFFF" TextWrapping="Wrap" FontFamily="Arial" FontSize="14" x:Name="WeatherNoServiceText"/>
        <Image Width="120" Height="120" x:Name="WeatherNoServiceImage2" Canvas.Top="87" Source="" />
      </Canvas>


                        </Canvas>
                    </Canvas>

                </Canvas>
            </Canvas>

            <Canvas x:Name="WeatherLoading" Visibility="Collapsed">
                <Canvas.Resources>
                    <Storyboard x:Name="WeatherLoadingIn" x:Key="WeatherLoadingIn" Completed="loadedIn">
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="WeatherLoading" Storyboard.TargetProperty="(UIElement.Opacity)">
                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                            <SplineDoubleKeyFrame KeyTime="00:00:00.8000000" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>

                    <Storyboard x:Name="WeatherLoadingOut" x:Key="WeatherLoadingOut" Completed="loadedOut">
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="WeatherLoading" Storyboard.TargetProperty="(UIElement.Opacity)">
                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                            <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </Canvas.Resources>

                <Rectangle Width="516" Height="200" Canvas.Top="60" Opacity="0.5" x:Name="WeatherLoadingBg" Visibility="Collapsed">
                    <Rectangle.Fill>
                        <RadialGradientBrush>
                            <GradientStop Color="#FF000000" Offset="0"/>
                        </RadialGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
                <TextBlock Foreground="#FFFFFFFF" Text="" x:Name="WeatherLoadingTxt" />
  </Canvas>

        </Canvas>


        <Canvas x:Name="subcat" Canvas.Top="-20" Canvas.Left="0" Canvas.ZIndex="20">
            <Canvas x:Name="innerSubcat" Canvas.Top="4" >
                <Rectangle Width="50" Height="20" Canvas.Left="0" Canvas.Top="0" x:Name="subcat_text_Hover" Opacity="0" >
                    <Rectangle.Fill>
                        <RadialGradientBrush >
                            <GradientStop Color="#55FFFFFF" Offset="0.3"/>
                            <GradientStop Color="#00FFFFFF" Offset="1"/>
                        </RadialGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
                <Rectangle Width="50" Height="20" Canvas.Left="0" Canvas.Top="0" x:Name="subcat_text_Prsd" Opacity="0" >
                    <Rectangle.Fill>
                        <RadialGradientBrush>
                            <GradientStop Color="#00FFFFFF" Offset="0"/>
                            <GradientStop Color="#00FFFFFF" Offset="1"/>
                        </RadialGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
                <TextBlock FontSize="20" FontFamily="Trebuchet MS" Text="Nachrichten" x:Name="subcat_text" Foreground="#ffffffff" Canvas.Left="0" Canvas.Top="0" Cursor="Hand" />
        <TextBlock FontSize="20" FontFamily="Trebuchet MS" Text="Nachrichten" x:Name="subcat_text2" Foreground="#ffffffff" Canvas.Left="-900" Canvas.Top="0" Cursor="Hand" />
    </Canvas>
            <Path Cursor="Hand" Canvas.Top="8" Stretch="Fill" StrokeThickness="5" Data="M1,10 L12,4 12,16 z" x:Name="subcat_main_left_btn" Opacity="1">
                <Path.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" >
                        <GradientStop Color="#FFFFFFFF" Offset="0"/>
                    </LinearGradientBrush>
                </Path.Fill>
            </Path>
            <Path Cursor="Hand" Canvas.Top="8" Stretch="Fill" StrokeThickness="5" Data="M1,10 L12,4 12,16 z" x:Name="subcat_main_right_btn" RenderTransformOrigin="0.5,0.5"  Opacity="1">
                <Path.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" >
                        <GradientStop Color="#FFFFFFFF" Offset="0"/>
                    </LinearGradientBrush>
                </Path.Fill>
                <Path.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="-1" ScaleY="1"/>
                        <SkewTransform AngleX="0" AngleY="0"/>
                        <RotateTransform Angle="0"/>
                        <TranslateTransform X="0" Y="0"/>
                    </TransformGroup>
                </Path.RenderTransform>
            </Path>
        </Canvas>

        <Canvas Canvas.Left="2" Canvas.Top="-45" x:Name="MSN-Startseite" Canvas.ZIndex="5" Cursor="Hand" >
            <Rectangle Width="50" Height="30" Canvas.Top="0" x:Name="MSN-Startseite_Hover" Opacity="0" >
                <Rectangle.Fill>
                    <RadialGradientBrush>
                        <GradientStop Color="#99FFFFFF" Offset="0"/>
                        <GradientStop Color="#00FFFFFF" Offset="1"/>
                    </RadialGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
            <Rectangle Width="50" Height="20" Canvas.Top="0" x:Name="MSN-Startseite_Prsd" Opacity="0" >
                <Rectangle.Fill>
                    <RadialGradientBrush>
                        <GradientStop Color="#00FFFFFF" Offset="0"/>
                        <GradientStop Color="#00FFFFFF" Offset="1"/>
                    </RadialGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
            <Image x:Name="msn_logo" Source="" Width="50" />
        </Canvas>

        <Canvas x:Name="Scrollbar" Width="10" Height="184" Canvas.Left="622" Canvas.Top="8" Opacity="0">
            <Rectangle x:Name="Scrollbar_Bg" Width="10" Height="164" RadiusX="4" RadiusY="4">
                <Rectangle.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FF000000" Offset="0"/>
                        <GradientStop Color="#FF3D3D3D" Offset="0.558"/>
                        <GradientStop Color="#FF060606" Offset="1"/>
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
            <Rectangle Fill="#FF000000" RenderTransformOrigin="0.5,0.5" x:Name="Btn_Scroll_Down" Width="10" Height="10" Stroke="#FFFFFFFF" RadiusX="0" RadiusY="2" Canvas.Top="194">
                <Rectangle.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="1" ScaleY="1"/>
                        <SkewTransform AngleX="0" AngleY="0"/>
                        <RotateTransform Angle="0"/>
                        <TranslateTransform X="0" Y="0"/>
                    </TransformGroup>
                </Rectangle.RenderTransform>
            </Rectangle>
            <Rectangle RenderTransformOrigin="0.5,0.5" x:Name="Btn_Scroll_Up" Width="10" Height="10" Stroke="#FFFFFFFF" RadiusX="0" RadiusY="2" Fill="#FF000000">
                <Rectangle.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="1" ScaleY="1"/>
                        <SkewTransform AngleX="0" AngleY="0"/>
                        <RotateTransform Angle="0"/>
                        <TranslateTransform X="0" Y="0"/>
                    </TransformGroup>
                </Rectangle.RenderTransform>
            </Rectangle>
            <Canvas x:Name="Btn_Scroll_Slider" Width="10" Height="30" Canvas.Top="10">
                <Rectangle RenderTransformOrigin="0.665,0.715" Cursor="None" x:Name="Btn_Scroll_Slider_Bg" Width="10" Height="30" RadiusX="5" RadiusY="5">
                    <Rectangle.Fill>
                        <LinearGradientBrush EndPoint="0,0.5" StartPoint="1,0.5" SpreadMethod="Pad" MappingMode="RelativeToBoundingBox">
                            <GradientStop Color="#FF414141" Offset="0"/>
                            <GradientStop Color="#FF7A7A7A" Offset="1"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
            </Canvas>
        </Canvas>

        <Canvas x:Name="NewsItemsContainer" Width="130" Height="198" Canvas.Left="3" Canvas.Top="8" Canvas.ZIndex="3">
            <Canvas.Clip>
                <RectangleGeometry x:Name="NewsItemsContainerClip" Rect="0,20,300,300" />
            </Canvas.Clip>
            <Rectangle Width="130" Height="198" RadiusX="5" RadiusY="5" x:Name="NewsItems_Bg" Stroke="#ff333333" StrokeThickness="1">
                <Rectangle.Fill>
                    <LinearGradientBrush EndPoint="0.474999994039536,0.523000001907349" StartPoint="0.47299998998642,0.181999996304512">
                        <GradientStop Color="#AA000000" Offset="0"/>
                        <GradientStop Color="#AA333333" Offset="0.549"/>
                        <GradientStop Color="#AA111111" Offset="0.57"/>
                        <GradientStop Color="#AA111111" Offset="0.7"/>
                        <GradientStop Color="#AA191919" Offset="1"/>
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>

            <Canvas x:Name="NewsImage" Width="104" Height="198" Canvas.Left="5" Canvas.Top="40" Canvas.ZIndex="1">

            </Canvas>

            <Canvas x:Name="Loading" Canvas.Top="100" Canvas.Left="50" Height="50">
                <Rectangle x:Name="Loading_Bar" Height="15" Width="10" Canvas.Left="2">
                    <Rectangle.Fill>
                        <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                            <GradientStop Color="#FFaaaadd" Offset="0"/>
                            <GradientStop Color="#FF888899" Offset="1"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
                <Rectangle x:Name="Loading_Stroke" Height="15" Width="200" Stroke="#ffaaaadd" StrokeThickness="2" RadiusX="2" RadiusY="2" />

                <Rectangle x:Name="Loading_Bar_refl" Height="15" Width="10" Canvas.Left="2" Canvas.Top="25">
                    <Rectangle.Fill>
                        <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                            <GradientStop Color="#FFaaaadd" Offset="0"/>
                            <GradientStop Color="#FF888899" Offset="1"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                    <Rectangle.OpacityMask>
                        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                            <GradientStop Color="#00000000" Offset="1.0" />
                            <GradientStop Color="#44FFFFFF" Offset="0.0" />
                        </LinearGradientBrush>
                    </Rectangle.OpacityMask>
                </Rectangle>
                <Rectangle x:Name="Loading_Stroke_refl" Height="15" Width="200" Stroke="#ffaaaadd" StrokeThickness="2" RadiusX="2" RadiusY="2" Canvas.Top="25" >
                    <Rectangle.OpacityMask>
                        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                            <GradientStop Color="#00000000" Offset="1.0" />
                            <GradientStop Color="#44FFFFFF" Offset="0.0" />
                        </LinearGradientBrush>
                    </Rectangle.OpacityMask>
                </Rectangle>
            </Canvas>
            <Canvas x:Name="NewsItems" Width="130" Canvas.ZIndex="1" Canvas.Left="122">
            </Canvas>

        </Canvas>

        <Canvas x:Name="SearchBar" Canvas.Top="200" Canvas.Left="15" Canvas.ZIndex="10">

            <TextBox x:Name="SearchBar_Txt" Canvas.Top="-2" Padding="0" Height="16" />
            <TextBox x:Name="SearchBar_hidden" Height="0" Width="0" />
            <Image x:Name="SE_logo" Height="16" Source="" Canvas.Top="0" Cursor="IBeam" />
            <Path x:Name="SearchBar_Cursor" Stroke="Black" StrokeThickness="2" Canvas.Left="4" Data="M0,2V16" Opacity="0" />
            <Canvas Width="20" x:Name="SearchBar_Btn" Cursor="Hand">

                <Image x:Name="BingButton" Height="19" Canvas.Top="1" Width="19" Source="" />
            </Canvas>
            <Canvas x:Name="SearchBar_Options" Cursor="Hand" Visibility="Collapsed"  Canvas.Top="50">
                <Rectangle Width="20" Height="20" RadiusX="10" RadiusY="10" >
                    <Rectangle.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFffffff" Offset="0"/>
                            <GradientStop Color="#ff333333" Offset="0.5"/>
                            <GradientStop Color="#FF777777" Offset="1"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
            </Canvas>
            <Canvas x:Name="SearchBar_Download" Cursor="Hand" Visibility="Collapsed"  Canvas.Top="50">
                <Rectangle Width="20" Height="20" RadiusX="10" RadiusY="10" >
                    <Rectangle.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFffffff" Offset="0"/>
                            <GradientStop Color="#ff333333" Offset="0.5"/>
                            <GradientStop Color="#FF777777" Offset="1"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
            </Canvas>
            <Canvas x:Name="SearchBar_Usage" Cursor="Hand" Visibility="Collapsed" Canvas.Top="50">
                <Rectangle Width="20" Height="20" RadiusX="10" RadiusY="10" >
                    <Rectangle.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFffffff" Offset="0"/>
                            <GradientStop Color="#ff333333" Offset="0.5"/>
                            <GradientStop Color="#FF777777" Offset="1"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
            </Canvas>
        </Canvas>

        <Canvas Canvas.Top="193" Canvas.Left="8" Canvas.ZIndex="12" x:Name="SearchBar_More_Canvas">
            <Canvas.Clip>
                <RectangleGeometry Rect="0,-60,900,59" />
            </Canvas.Clip>
            <Canvas x:Name="SearchBar_More" Height="32" Canvas.Top="0">
                <Rectangle x:Name="SearchBar_More_Bg" RadiusX="2" RadiusY="2" Width="280" Height="32">
                    <Rectangle.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" >
                            <GradientStop Color="#FF71A7CC" Offset="0"/>
                            <GradientStop Color="#FF71A7CC" Offset="0.147"/>
                            <GradientStop Color="#FF2473A9" Offset="0.491"/>
                            <GradientStop Color="#FF075690" Offset="0.522"/>
                            <GradientStop Color="#FF5272B7" Offset="1"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
                <Canvas x:Name="SearchBar_More_Container" />
            </Canvas>
        </Canvas>



        <Canvas Width="218" Height="20" Canvas.Top="8" Canvas.Left="3" x:Name="Subcat_Scroll" Canvas.ZIndex="13">
            <Rectangle Width="218" Height="20" RadiusX="5" RadiusY="5" x:Name="SubCats_bg_black" Opacity="0.7" Fill="#ff000000" >
            </Rectangle>
            <Rectangle Width="218" Height="20" RadiusX="5" RadiusY="5" x:Name="SubCats_bg" Opacity="0.5" Stroke="#33ffffff">
                <Rectangle.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" >
                        <GradientStop Color="#7FFFFFFF" Offset="0"/>
                        <GradientStop Color="#99FFFFFF" Offset="0.134"/>
                        <GradientStop Color="#7FFFFFFF" Offset="0.299"/>
                        <GradientStop Color="#26FFFFFF" Offset="0.562"/>
                        <GradientStop Color="#66FFFFFF" Offset="0.496"/>
                        <GradientStop Color="#26FFFFFF" Offset="1"/>
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
            <Path Cursor="Hand" Canvas.Top="1" Stretch="Fill" StrokeThickness="5" Data="M1,10 L15,1 15,19 z" x:Name="subcat_left_btn" Opacity="1">
                <Path.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" >
                        <GradientStop Color="#7FFFFFFF" Offset="0"/>
                        <GradientStop Color="#99FFFFFF" Offset="0.134"/>
                        <GradientStop Color="#7FFFFFFF" Offset="0.299"/>
                        <GradientStop Color="#26FFFFFF" Offset="0.562"/>
                        <GradientStop Color="#66FFFFFF" Offset="0.496"/>
                        <GradientStop Color="#26FFFFFF" Offset="1"/>
                    </LinearGradientBrush>
                </Path.Fill>
            </Path>
            <Path Cursor="Hand" Canvas.Top="1" Stretch="Fill" StrokeThickness="5" Data="M1,10 L15,1 15,19 z" x:Name="subcat_right_btn" RenderTransformOrigin="0.5,0.5" Canvas.Left="206.809" Opacity="1">
                <Path.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" >
                        <GradientStop Color="#7FFFFFFF" Offset="0"/>
                        <GradientStop Color="#99FFFFFF" Offset="0.134"/>
                        <GradientStop Color="#7FFFFFFF" Offset="0.299"/>
                        <GradientStop Color="#26FFFFFF" Offset="0.562"/>
                        <GradientStop Color="#66FFFFFF" Offset="0.496"/>
                        <GradientStop Color="#26FFFFFF" Offset="1"/>
                    </LinearGradientBrush>
                </Path.Fill>
                <Path.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="-1" ScaleY="1"/>
                        <SkewTransform AngleX="0" AngleY="0"/>
                        <RotateTransform Angle="0"/>
                        <TranslateTransform X="0" Y="0"/>
                    </TransformGroup>
                </Path.RenderTransform>
            </Path>
        </Canvas>

        <Canvas x:Name="SubCats_Container" Height="20" Canvas.Left="5" Canvas.Top="8" Canvas.ZIndex="15">
            <Canvas.Clip>
                <RectangleGeometry x:Name="Subcat_Clip" Rect="15,15,900,-15" />
            </Canvas.Clip>

            <Canvas Width="218" x:Name="SubCats" Canvas.ZIndex="15">
            </Canvas>

        </Canvas>
    </Canvas>

</Canvas>
</script>

<style type="text/css">
body 
{
    margin: 0px;
    width: 390px;
    height: 280px;
    background: none;
}

</style>

</head>
<body> 

<div id="MSNSilverlightHost" >
  Hier entsteht das MSN Gadget
</div>
<div id="click" style="display:none"><a href="http://msn.de">MSN Startseite</a></div>
<script type="text/javascript">

function createSL() {
var scene = new MSNWidget.Page();
var obj_host = document.getElementById("MSNSilverlightHost");
Silverlight.createObjectEx({
source: "#MSN_XAML",
parentElement: obj_host,
id: "MSNSilverlight",
properties: {
width: "135",
height: "280",
version: '2.0',
isWindowless: 'true',
background:'#00000000'
},
events: {
onLoad: scene.handleLoad,
onError: xaml_error,
onResize: GUI.update }
});
}

var installExperienceHTML = '<div style="position:auto; text-align:left; background-repeat:no-repeat; height:477px; background-image:url(images/widget-bg.jpg);">';
installExperienceHTML += '<div>';
installExperienceHTML += '<div id="InstallPromptDiv" style="padding-left: 80px; padding-top: 60px;"> </div> </div> <div id="PostInstallGuidance"';
installExperienceHTML += 'style="width:auto; font-family:sans-serif; height:auto; padding-top:20px;text-align:center; color:#3366ff; ';
installExperienceHTML += 'font-weight:normal; font-size:11pt"></div> </div>';

Silverlight.InstallAndCreateSilverlight('2.0',
document.getElementById('MSNSilverlightHost'),
installExperienceHTML,
'InstallPromptDiv',
createSL);

var PostInstallGuidance = document.getElementById('PostInstallGuidance');
if ( document.getElementById('PostInstallGuidance') ) {
{
if ( Silverlight.available ) {
PostInstallGuidance.innerHTML="When installation is complete, restart your browser to activate your Silverlight content.";
} else { PostInstallGuidance.innerHTML= ""; }
}
}
</script>


<div id="errorLocation"></div>
</body>
</html>